Reputation: 11
I want: all links which not contained filename (not .html, .jpg, .png, .css) redirect with state 301 to directory, for example: http://mysite.com/article -> http://mysite.com/article/ But http://mysite.com/article/article-15.html not redirects. What regulat expression I must write to .htaccess for adding slash to virtual directories?
Upvotes: 0
Views: 1137
Reputation: 63529
MB's RewriteRule above will fail on paths like /a
because it needs to match at least two characters after the slash. Moreover it only matches on top directory URLs.
RewriteRule ^(([^\/]+\/)*[^\/\.]+)$ http://%{HTTP_HOST}/$1/ [R=301,L]
Is the purpose of this to reduce history pollution/false negatives?
Upvotes: 0
Reputation: 7533
I think the following might work:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
When it comes to mod_rewrite I can never be sure without testing though...
Upvotes: 2
Reputation:
Clarification needed:
Given the url: http://server/path/file
Does that get redirected to: http://server/path/
Or does it get redirected to: http://server/path/file/
As in: Do you want the redirects to go to the parent path, or do you just want to add a slash and assume directory out of the current path?
Upvotes: 1