Mod Rewrite与Wordpress重写规则冲突?
在我的网站上有一个带有短代码的页面,在打印内容之前读取3个参数。该页面如下所示: /collaboratori?collaboratore=6&n=Mario&c=Rossi 我想将其转换为一个对搜索引擎优化友好的url,如下所示: /profilo collaboratore/6/Mario/Rossi 我正在使用以下修改重写规则:Mod Rewrite与Wordpress重写规则冲突?,wordpress,apache,.htaccess,mod-rewrite,friendly-url,Wordpress,Apache,.htaccess,Mod Rewrite,Friendly Url,在我的网站上有一个带有短代码的页面,在打印内容之前读取3个参数。该页面如下所示: /collaboratori?collaboratore=6&n=Mario&c=Rossi 我想将其转换为一个对搜索引擎优化友好的url,如下所示: /profilo collaboratore/6/Mario/Rossi 我正在使用以下修改重写规则: RewriteEngine On RewriteRule ^profilo-collaboratore/([^/]*)/([^/]*)/([^/]*)$ /col
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>
重新启动发动机
重写规则^profilo collaboratore/([^/]*)/([^/]*)/([^/]*)$/collaboratori?collaboratore=$1&n=$2&c=$3[L]
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
我哪里错了
非常感谢看来正则表达式有问题了 尝试下面的规则,它应该会工作
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
url是否应该由Wordpress处理(例如,它是Wordpress插件吗)?是的,它是由meWordpress编写的插件,它依赖于地址栏中的url,而不是它被重写的url。这意味着在.htaccess文件中使用mod_rewrite重写url不会产生任何效果。我该怎么做?你有一些例子吗?嗨,坎南,谢谢你,但它不起作用。正如@Sumurai8之前所说,这与Wordpress引擎中的重写规则相冲突。这不是一个可以通过使用.htaccess解决的问题。如果我能找到解决方案,我会更新这个问题