我有这样的数百个链接:
http://www.domain.com/index.php?tag=value
我想将所有链接redirect到
http://www.domain.com/value/
例:
Link1 http://www.domain.com/index.php?tag=LW1fdX49tR
redirect到: http://www.domain.com/LW1fdX49tR/
: http://www.domain.com/LW1fdX49tR/
Link2 http://www.domain.com/index.php?tag=A3kh0QLIrc
redirect到: http://www.domain.com/A3kh0QLIrc/
: http://www.domain.com/A3kh0QLIrc/
Link3 http://www.domain.com/index.php?tag=vXwNR4U9qY
redirect到: http://www.domain.com/vXwNR4U9qY/
: http://www.domain.com/vXwNR4U9qY/
等等
我怎样才能做到这一点? 谢谢!
除了重定向请求之外,您可能还想确保新的url实际上也可以工作。 你将需要外部重定向和内部重写。 在下面的例子中,我使用THE_REQUEST技巧来触发规则,如果它是实际的请求URL,而不是内部重写。 需要防止无限循环。
#External redirect with THE_REQUEST trick; change R to R=301 when everything works correctly RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?tag=(.*)\ HTTP RewriteRule ^ /%2? [R,L] #Internal rewrite RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?tag=$1 [L]