在编写RewriteCond或RewriteRules时是否可以链接或组合查询字符串?
目前我在.htaccess文件中有这个...
RewriteCond %{QUERY_STRING} tiger [OR]
RewriteCond %{REQUEST_URI} tiger
RewriteRule ^ http://www.example.com/news/? [L,R=301]
RewriteCond %{QUERY_STRING} lion [OR]
RewriteCond %{REQUEST_URI} lion
RewriteRule ^ http://www.example.com/news/? [L,R=301]
RewriteCond %{QUERY_STRING} cheetah [OR]
RewriteCond %{REQUEST_URI} cheetah
RewriteRule ^ http://www.example.com/news/? [L,R=301]
所有三场比赛都将转到同一目的地。有可能做这样的事情,还是我需要将它们作为单独的行保留?
RewriteCond %{QUERY_STRING} (tiger, lion, cheetah) [OR]
RewriteCond %{REQUEST_URI} (tiger, lion, cheetah)
RewriteRule ^ http://www.example.com/news/? [L,R=301]
这是我的htaccess文件......
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
答案 0 :(得分:1)
您可以使用正则表达式替换:
RewriteCond %{QUERY_STRING} (tiger|lion|cheetah) [NC,OR]
RewriteCond %{REQUEST_URI} (tiger|lion|cheetah) [NC]
RewriteRule ^ http://www.example.com/news/? [L,R=301]