我试图在我们的Wordpress多站点设置中为htaccess文件添加一些自定义重写规则,但无论我把它们放在哪里,它们都没有任何效果 - 我已经检查了在http://htaccess.madewithlove.be/上使用几个测试网址来统治自己,并且它们按预期工作,但是当放入htaccess文件时,没有任何事情发生。这是因为Wordpress重写功能的工作方式吗?
以下是我的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]
# Redirect Test subscription page - needed for subscription ad.
Redirect 301 /subscriptions/test/ /subscriptions/product-category/test/
Redirect 301 /subscriptions/test /subscriptions/product-category/test/
# Redirect the Test 2 stuff as no longer selling them
Redirect 301 /subscriptions/product-category/test2/ /subscriptions/
我要重定向的页面是......
http://www.example.com/tigers-strengthen-its-position-in-market/testing1/
http://www.example.com/tigers-strengthen-its-position-in-market/testing2/
http://www.example.com/tigers-strengthen-its-position-in-market/testing2/
我希望将它们重定向到...
http://www.example.com/news/
我的重定向规则是......
RewriteRule ^tiger-bills-strengthens-position(.*) /news/ [R=301,L]
答案 0 :(得分:0)
我已经设法通过在RewriteCond中使用正则表达式更改来实现此功能。工作代码是......
RewriteCond %{QUERY_STRING} (tigers\-strengthen|testing1|testing2) [NC,OR]
RewriteCond %{REQUEST_URI} (tigers\-strengthen|testing1|testing2) [NC]
RewriteRule ^ http://www.example.com/news/? [L,R=301]