开发者

Is it possible to "hide" a sub directory after rewriting root to that directory?

What I'm trying to accomplish is basically hide the fact that the page is served from a subdirectory.

I currently have the following .htaccess

RewriteEngine On
RewriteBase / 
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule (.*) /blog/$1

This does what I want. It serves pages from /blog while giving the user the impression of being in the root directory.

However if the user visits http://www.example.com/blog they get the same page. If possible I would actually like them to get /blog/blog.

The main reason this worries me is not because 开发者_如何学Pythonof real users but because of robots that might index the page with the wrong URL.


This is possible but you have to cheat a little. Essentially THE_REQUEST never changes during rewriting so you can test for that.

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /blog
RewriteRule . - [F]
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule (.*) /blog/$1

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜