简体   繁体   English

如何删除? 从网址使用htaccess

[英]How to remove ? from the url using htaccess

I having a URL http://www.domain.com/postname/?a_different_world 我有一个网址http://www.domain.com/postname/?a_different_world

I need to change it to http://www.domain.com/postname/a_different_world 我需要将其更改为http://www.domain.com/postname/a_different_world

How to remove ? 如何删除? from the URL using Htacccess(Wordpress) 使用Htacccess(Wordpress)从URL中获取

I use following htaccess code. 我使用以下htaccess代码。 But it is not working 但这不起作用

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

The rule match string strips out the query string (everything after the ?). 规则匹配字符串会去除查询字符串(?之后的所有内容)。 Hence you want to drop the ? 因此,您想删除? and explicitly use the query string like this (instead of your last rule) 并显式使用这样的查询字符串(而不是最后一条规则)

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

Note that you should drop the leading / as this won't match as .htaccess rule match string drops the leading /; 请注意,您应该删除前导/,因为它不会匹配,因为.htaccess规则匹配字符串会删除前导/;。 also note the ? 还注意了吗? in the replacement pattern and omission of the QSA flag as you don't want to append the query string. 在QSA标志的替换模式和不作为,你不想追加查询字符串。

Also move this rule above the previous cond/rule as this second rule will fire on your postname pattern so you'll never get to this rule unless you move it up one. 另外,请将此规则移至上一个条件/规则上方,因为第二个规则将在您的邮递姓名模式上触发,因此除非您将其上移一个,否则您永远不会使用此规则。

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

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