开发者

htaccess trailing slash

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /dir/index.php?category=$1&link=$2 [L]
RewriteCond %{REQUEST_URI} !\.[^./]+$ 
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.mydomain.com/dir/$1/$2 [R=301,L]

I'm having a problem with this one, I hope someone will help me.

www.domain.com/dir/category/

works well, but when it comes to a second variable

www.domain.com/dir/category/variable/

it doesn't work, but if I remove the last slash, it works...

EDIT----------------------------

This works fine so far.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ /dir/index.php?category=$1&link=$2 [L]


RewriteCond %{REQUEST_URI} !\.[^./]+$ 
RewriteCond %{REQUEST_URI} !(.*)/$
Rewrite开发者_如何学GoRule ^(.*)$ http://www.omain.com/dir/$1/$2 [R=301,L]


Try replacing the first RewriteRule by this one:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]*)/([^/]*)/?$ /dir/index.php?category=$1&link=$2 [L]

This explicitly allows a trailing slash at the end.


Change

RewriteRule ^([^/]*)/([^/]*)$ /dir/index.php?category=$1&link=$2 [L]

To

RewriteRule ^([^/]*)/([^/]*)([^\.css|\.js])/?$ /dir/index.php?category=$1&link=$2$3 [NC,L]

EDIT This is a massive cop out and I will hopefully update this at some point with a single line rule that does everything, but for now this will work (my brain is not working properly any more). This assumes that your JS is in a directory called 'js' and CSS is in a directory called 'css'. The order of these rules is important!

RewriteRule ^(css|js)/(.*)$ /dir/$1/$2 [L]
RewriteRule ^([^/]*)/([^/]*)/?$ /dir/index.php?category=$1&link=$2 [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜