Search

I seem to be having problems with my trailing slash rewrite rule.

There’s a link on my site to download a file and a trailing slash is being added, thus making the file undownloadable.

My htaccess contains the rules:

CHECK FOR TRAILING SLASH - Will ignore files

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

The url which is having a trailing slash added is:

/uploaded/press-kits/shockwaves.zip/

Would it be correct to assume I need an htaccess inside the uploaded or press-kits folder, or that I can adjust the afore rewrite rules to include this folder?

Any suggestions are very welcome, ta :)

If a trailing slash is added to your URL, this simply means that your URL ir wrong! Symphony’s rewrite rules do not apply to physical files. (See the first line of your code example.)

I have run into this rather often. In every single case I had a typo in my URL…

Actually I am running in the same issue, but regarding Old URL rewrites :

I need to rewrite some old urls: e.g. foo.com/index.htm should point to foo.com

At the moment I am trying to add a Redirect rule to my .htaccess but it fails and my guess is that is has to do with the ‘trailing-slash’ redirect etc. Redirect 301 /index.htm http://www.mysite.com is not picked up.

the result is http://www.mysite.com/index.htm/ (as if index.htm is no file).

How should I go about adding Redirect rules to my .htaccess?

UPDATE I actually found what I needed in this thread. Adding a separate <IfModule> with the RewriteRule rules before the Symphony rules does the trick.

Also: it seems there’s a lot of (301) redirection going on: adding trailing slash (301) etc. Does this not have a potential negative effect on performance and googlebot?

It’s actually better to use Apache’s Redirect 301 directive for this kind of thing, leaving the mod_rewrite stuff for the new site. That way the Apache redirects are dealt with before any RewriteRules are considered.

Can you post your .htaccess? I’ve done a lot of work recently with these things and may be able to help…

Michael is very right though, there is a problem with the file’s URL if it is having a slash appended, as MIME types on the server should pick this up as a file, therefore the following condition should ignore it

RewriteCond %{REQUEST_FILENAME} !-f

You may have to specifically define .zip files in the .htaccess, which isn’t difficult…

Quick update, try adding

AddType application/octet-stream zip

to the top of your htaccess, it should force download zip files.

@designermonkey thanks for the reply.

With some adjustments I’ve got the site working as planned. The ‘files’ (/index.htm etc) are picked up correctly, so I suspect it was an issue with the rewrites, not the apache file handling.

What do you mean with “Apache’s Redirect 301 directive”? Do you mean the Apache directives in e.g. the httpd.conf? In that case: I’ve got no access to those since I’m on shared hosting. A rewrite rule in the .htaccess seems the best I can do.

I am a little uncertain about all those (combined) 301 rewrites though: adding-trailer-slashes, redirecting-to-symphony-page, etc.

Anyway, thanks for the offer: my (adjusted for privacy) htaccess can be found here: http://pastebin.com/U9vSSgRZ

In your htaccess, Apache Redirects are done as follows (an example Symphony htaccess)

Redirect 301 /index.htm http://example.com/

### Symphony 2.0.x ###
Options +FollowSymlinks -Indexes

<IfModule mod_rewrite.c>

    RewriteEngine on
    RewriteBase /

### Redirects here

...

They’re handled by Apache and not modrewrite so are dealt with before modrewrite rules take effect, you posted it earlier so you know it…

I’ve made my version (Pastebin) of the redirects for your legacy urls, but if it’s working fine now, then I’d just leave it, it’s a dark art…

Thanks designermonkey, all seems well so I will not change it. It’s a dark art indeed and I plan not to meddle with it too much ;-P

SOLVED The issue has to do with a legacy Default Page Setting in Google Analytics: http://vlst.nl/x/67

(designermonkey) There’s one strange thing I just noticed.

My site seems to work correctly: all legacy URL’s are redirected properly etc. However, when I check my Google Analytics the URL’s show up with index.htm at the end.

E.g. the following URL exists and works: www.site.com/about-us/

In GA, however, this URL shows up as www.site.com/about-us/**index.htm** This URL does not work (redirects to www.site.com/about-us/index.htm**/** and returns 404…)

I can’t see how my .htaccess has much to do with this, but maybe I’m overlooking something?

The other thing I’m thinking about is some caching (old visitors of the site)?

Has anybody any idea what could cause GA to log my URL’s as such? And how to fix it, if necessary.

It seems the visitors have no trouble actually browsing the site, even though the URL’s in GA return a 404, so I believe it is mostly an issue with Google logging the URL’s. The visitors will probably simply visit the correct URL’s.

I’ve given up Google Analytics in favour of Piwik

But well spotted!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details