2015-05-12 52 views
1

是否可以将网站的所有页面重定向到该网站的子目录,并将原始URL保留在重定向URL的末尾?将所有页面重定向到网站的子目录

喜欢的东西:

www.example.com/hello-word -> www.example.com/blog/hello-world 

或者换句话说,一个通配符重定向到一个子文件,我想。

回答

1

放置.htaccess文件的根目录中的规则如下:

RewriteEngine On 
# Redirect urls that do not contain path 
RewriteRule ^$ /blog/ [R,L] 
# Redirect urls that do not map to a directory and file, and do not begin with /blog/ 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(?!blog/)(.*) /blog/$1 [R,L] 

如果有必要,彻底测试你的规则替换后RR=301

相关问题