开发者

.htaccess subdomain to directory: problem with trailing slash

I've got a problem with my htaccess file. The last part of the file is supposed to redirect filip.novotny.je to /subdom/filip/. When the URL ends with a slash, everything is fine but when it doesn't, it reveals the ugly subdomain directory in the address bar. Does anyone know why that might be?

Try it yourself here: with x without trailing slash

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.novotny.je$ [NC]
RewriteRule ^(.*)$ http://novotny.je/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.filip.novotny.je$ [NC]
RewriteRule ^(.*)$ http://filip.novotny.je/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^novotny.je$ [nc]
RewriteRule ^(.*)$ http://filip.novotny.je/$1 [r=301]

# cele domeny (aliasy)
# RewriteCond %{REQUEST_URI} !^/domains/
# RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
# RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
# RewriteRule (.*) /domains/%2/$1 [L]

# subdomeny (s nebo bez www na zacatku)
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
Rewr开发者_运维技巧iteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) /subdom/%2/$1 [L]


I recently had a very similar issue, but in IIS7. Here is my resolution, converted to .htaccess syntax. I hope it works for you.

RewriteCond %{REQUEST_FILENAME}  -d
RewriteRule ^(.+[^/])$  $1/  [R]

Basically, the condition is that the request is a directory and the rewrite matches all requests without a trailing slash and outputs with the trailing slash.


Just add a rewrite rule to add a slash after each url. Something like

RewriteCond %{REQUEST_URI}  ^([^+?&]+[^/])$
RewriteRule ^([^+?]+[^/])$ $1/  [R,L]

Add this before all the rules you have given. This will convert all the urls from a.com/b to a.com/b/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜