Forum Moderators: phranque
So my .htaccess file looks like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI}!^[^.]*/$
RewriteRule (.+) /$1/ [R=301,L]
But when I try it, I watch my browser go through a process like this...
[domain.com...]
[domain.com...]
[domain.com...]
[domain.com...]
[domain.com...]
and so on until finally my browser gives up after many /s appear in the address.
It appears I have copied the the code correctly from the example jdMorgan provided. I don't understand regular expressions so there could be a problem I don't see.
Can anyone help? Thank you.
I found the solution here...
[webmasterworld.com...]
I changed my .htaccess file to use this instead
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ /$1/ [R=301,L] Now it works.
Welcome to WebmasterWorld!
There's a bug in that code. Try this instead:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(/$¦\.)
RewriteRule (.+) http://www.example.com/$1/ [R=301,L]
Also, why does "index.php" suddenly appear in the URL? That is not a function of the code above, and should not be happening.
a regular expressions tutorial is available from a link in our forum charter, and a regex tutorial specific to mod_rewrite is also available in the library.
Jim
For example...
[domain.com...]
becomes
[domain.com...]
but then Safari complains...
[b]Safari can’t open the page.[/b]
Too many redirects occurred trying to open “http://domain.com/products/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page. I guess I do need some .htaccess help afterall. Thank you.
Also, why does "index.php" suddenly appear in the URL? That is not a function of the code above, and should not be happening.
I don't know the answer to this. I have some RedirectMatch 301 lines following the RewriteRule stuff (to catch old dead links), but none of them add index.php. I can only imagine that it is something that our web host does?
The proper way to associate the file index.php with requests for the "/" local URL-path is to use the DirectoryIndex [httpd.apache.org] directive, which will not expose the filename. E.G.
DirectoryIndex index.php
Jim