1
是否可以将网站的所有页面重定向到该网站的子目录,并将原始URL保留在重定向URL的末尾?将所有页面重定向到网站的子目录
喜欢的东西:
www.example.com/hello-word -> www.example.com/blog/hello-world
或者换句话说,一个通配符重定向到一个子文件,我想。
是否可以将网站的所有页面重定向到该网站的子目录,并将原始URL保留在重定向URL的末尾?将所有页面重定向到网站的子目录
喜欢的东西:
www.example.com/hello-word -> www.example.com/blog/hello-world
或者换句话说,一个通配符重定向到一个子文件,我想。
放置.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]
如果有必要,彻底测试你的规则替换后R
与R=301
。
试试这个:
RedirectMatch 301 ^/(.*)/?$ http://example.com/blog/$1
http://www.example.com/anything会重定向到http://www.example.com/blog/anything
什么'HTTP:// www.example.com /博客/ anything'? –
这意味着模式匹配的任何字符, – starkeen