I made this .htaccess file to try to remove final slash on links, but it not remove and no redirect o anything else, if you access for example to: mydomain.com/fruit it redirects to mydomain.com/fruit/ and I want just the opposite (fruit directory is an example, I have a lots of its and inside of each one I have an index.php file or other kind of files, just a few are empty).
I’ve been tried two different ways (copied from some websites), and no one works as I want.
Code one:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule ^ http://www.mydomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)$
RewriteRule (.*) http://www.mydomain.com/$1 [L,R=301]
Code two:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule ^ http://www.mydomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)$
RewriteRule (.*) http://www.mydomain.com/$1 [L,R=301]
My actual file (but with my real domain):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule ^ http://www.mydomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/+$ http://www.mydomain.com/$1 [L,R=301]
Options All -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
If I comment this line: RewriteCond %{REQUEST_FILENAME} !-d Chrome gives me an error: Error 310 (net::ERR_TOO_MANY_REDIRECTS).
Can anyone help me with the code of my .htaccess file?
Thanks in advanced.
You should read this on the trailing slash added by Apache webserver
http://httpd.apache.org/docs/current/mod/mod_dir.html
Hope this helps