views:

883

answers:

3

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?

+1  A: 

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?

I want add slash only: http://server/path/file -> http://server/path/file/
starkeen
+1  A: 

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...

MB
A: 

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?

eyelidlessness