.htaccess将root / old / variable重定向到root / new / same_variable

时间:2014-11-21 14:34:31

标签: php .htaccess

网址:

www.sub.example.com/old/id/345 (345 is post id)

所需网址:

www.sub.example.com/new/345

试过这个但不起作用:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/old/id/(.*)$
RewriteRule ^(.*) http://sub.example.com/new/%1 [R=302,NC]

谢谢!

2 个答案:

答案 0 :(得分:0)

尝试:

RewriteRule ^/old/id/(.*)$ http://sub.example.com/new/$1 [R=302,NC]

确保您允许mod_rewrite

答案 1 :(得分:0)

您可以在根目录中使用此规则.htaccess:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?sub\.example\.com$ [NC]
RewriteRule ^old/id/(.+)$ /new/%1 [R=302,NC]
相关问题