我的网址http://www.domain.com/postname/?a_different_world
我需要把它改成http://www.domain.com/postname/a_different_world
如何移除?从使用htacccess的url(wordpress)
我使用以下htaccess代码。但它不起作用

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php-$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /domain.com/index.php [L]
RewriteRule ^/postname/([0-9]+)$ /? $1 [L,QSA]

最佳答案

规则匹配字符串去掉查询字符串(后面的所有内容?)所以你想放弃?并显式地使用这样的查询字符串(而不是最后一条规则)

RewriteCond %{QUERY_STRING} ^([\w\-]+)$
RewriteRule ^postname/$ postname/%1?   [L]

请注意,应该删除前导/因为这与as不匹配。htaccess rule match string删除前导/;还要注意?在替换模式中省略qsa标志,因为您不想追加查询字符串。
同时将此规则移到上一个cond/rule之上,因为第二个规则将在您的postname模式上触发,所以除非将其移到上一个规则,否则您将永远无法访问此规则。

关于wordpress - 怎么删除?来自网址使用htaccess,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12598802/

10-13 01:02