1

I've been playing around with this for a while, but I'm still not sure if this is even possible.

I want a url to point to a different location on my webserver, but not change the url in the address bar.

Ex:

tp.test.com would access test.com/tp/hi

and subsequent urls:

tp.test.com/foo would point to test.com/tp/hi/foo

Ive been trying to achieve this using RewriteCond and RewriteRule and playing around with the flags for RewriteRule but haven't had any success at all.

Edit: This is what I had tried...

RewriteRule ^tp.test.com/blog/$ http://tp.test.com/tp/hi/$1 [r=301,L]

4

1 回答 1

0

尝试将此添加到文档根目录中的 htaccess 文件中:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/tp/hi%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/tp/hi%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}/tp/hi%{REQUEST_URI} -l
RewriteRule ^(.*)$ /tp/hi/$1 [L]

编辑:

由于您必须明确说明您在 URI 中实际需要的内容,因此上述方法行不通。

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/blog/(.*)$
RewriteCond %{DOCUMENT_ROOT}/tp/hi/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/tp/hi/%1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/tp/hi/%1 -l
RewriteRule ^blog/(.*)$ /tp/hi/$1 [L]
于 2013-01-28T19:23:49.883 回答