【问题标题】:Using custom rewrite rules on Wordpress multisite htaccess file在 Wordpress 多站点 htaccess 文件上使用自定义重写规则
【发布时间】:2015-06-02 09:54:33
【问题描述】:

我正在尝试在我们的 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]

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite


    【解决方案1】:

    我已经设法通过在 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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 2012-06-03
      • 2013-05-22
      • 1970-01-01
      相关资源
      最近更新 更多