简体   繁体   English

在Wordpress多站点htaccess文件上使用自定义重写规则

[英]Using custom rewrite rules on Wordpress multisite htaccess file

I'm trying to add a couple of custom rewrite rules to the htaccess file on our Wordpress multisite setup but no matter where I put them they aren't having any effect - I've checked the rule itself with a couple of test urls on http://htaccess.madewithlove.be/ and they work as intended but when put into the htaccess file nothing is happening. 我正在尝试在Wordpress多站点设置上的htaccess文件中添加一些自定义重写规则,但是无论我将它们放在何处都没有任何效果-我已经在几个测试网址上检查了规则本身http://htaccess.madewithlove.be/ ,它们可以按预期工作,但是当放入htaccess文件时,没有任何反应。 Is this because of the way the Wordpress rewrite function works? 这是因为Wordpress重写功能的工作方式吗?

Here is the content of my htaccess file… 这是我的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/

The pages I want to redirect are… 我要重定向的页面是…

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/

and I want to redirect them to… 我想将他们重定向到...

http://www.example.com/news/

My redirect rule is… 我的重定向规则是…

RewriteRule ^tiger-bills-strengthens-position(.*) /news/ [R=301,L]

I have managed to get this working by using regex alteration in RewriteCond. 我设法通过在RewriteCond中使用正则表达式更改来使此工作正常。 Working code is… 工作代码是…

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM