我想创建一个动态规则(可能是.htaccess的),将页面从以下位置重定向:
https://www.example.com/dir/search?q=stack+overflow至
https://www.example.com/dir/stack-overflow我知道我需要一个/dir文件夹
我试着用这个
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)\. search?q=$1不起作用。
发布于 2017-10-10 04:00:43
我假设您的意思是从/dir/search?q=stack-overflow到/dir/stack-overflow的301重定向,也就是说,如果用户输入https://www.example.com/dir/search?q=stack-overflow,浏览器的URL将更改为https://www.example.com/dir/stack-overflow。问题是,/dir/stack-overflow是一个真实的文件夹或文件吗?我不这么认为,因此您必须将/dir/stack-overflow重写回/dir/search?q=stack-overflow。
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^q=([^&]*)
RewriteRule ^/?dir/search/?$ /dir/%1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/?dir/search/?$ [NC]
RewriteRule ^/?dir/([^/?]+)/?$ /dir/search?q=$1 [L]如果你不想重写,也不想删除最后两行。
https://stackoverflow.com/questions/46631729
复制相似问题