Mod Rewrite与Wordpress重写规则相冲突?

时间:2015-01-24 09:18:51

标签: wordpress apache .htaccess mod-rewrite friendly-url

在我的网站上有一个带有短代码的页面,在打印内容之前会读取3个参数。该页面如下所示:

  

/ collaboratori collaboratore = 6&安培; N =马里奥和C =罗西

我想将其转换为 SEO友好网址,如下所示:

  

/ PROFILO-collaboratore / 6 /马里奥/罗西

我使用以下 Mod重写规则

RewriteEngine On
RewriteRule ^profilo-collaboratore/([^/]*)/([^/]*)/([^/]*)$ /collaboratori?collaboratore=$1&n=$2&c=$3 [L]

但是当我尝试加载/ profilo-collaboratore / 6 / Mario / Rossi时,Web服务器返回 404错误代码,Wordpress向我显示404错误页面

我的.htaccess是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^profilo-collaboratore/([^/]*)/([^/]*)/([^/]*)$ /collaboratori?collaboratore=$1&n=$2&c=$3 [L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

哪里错了?

非常感谢

1 个答案:

答案 0 :(得分:0)

看起来正则表达式存在问题。

尝试以下规则,它应该有效。

RewriteRule ^/profilo-collaboratore/(\w+)/(\w+)/(\w+) /collaboratori?collaboratore=$1&n=$2&c=$3 [NC]

我通过添加[R]标志来测试它,以便在重定向期间查看重写的URL。

$ curl -IL http://localhost/profilo-collaboratore/6/Mario/Rossi
HTTP/1.1 302 Found
Date: Sat, 24 Jan 2015 15:03:24 GMT
Server: Apache/2.4.10 (Unix) OpenSSL/1.0.1e
Location: http://localhost/collaboratori?collaboratore=6&n=Mario&c=Rossi
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 404 Not Found
Date: Sat, 24 Jan 2015 15:03:24 GMT
Server: Apache/2.4.10 (Unix) OpenSSL/1.0.1e
Last-Modified: Wed, 24 Dec 2014 08:11:27 GMT
ETag: "13f-50af1d6a1b74d"
Accept-Ranges: bytes
Content-Length: 319
Content-Type: text/html