如何删除?从URL使用的htaccess的 [英] How to remove ? from the url using htaccess

查看:214
本文介绍了如何删除?从URL使用的htaccess的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我需要将其更改为 http://www.domain.com/postname/a_different_world

如何删除?使用该URL Htacccess(字preSS)

我用下面的htaccess code。但它不工作

  RewriteEngine叙述上
的RewriteBase /
重写规则^指数\ .php- $  -  [L]
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则。 /domain.com/index.php [L]
重写规则^ / postname /([0-9] +)$ /? $ 1 [L,QSA]
 

解决方案

规则匹配字符串剔除了查询字符串(一切后?)。因此,你要删除的?并明确使用(而不是你的最后一条规则)这样的查询字符串

 的RewriteCond%{QUERY_STRING} ^([\ w \  - ] +)$
重写规则^ postname / $ postname /%1? [L]
 

请注意,你应该放下领先/ AS作为的.htaccess规则匹配的字符串,这将不匹配的下降主要/;还要注意的?在QSA标志的更换方式和不作为你的的要追加查询字符串。

也将高于previous电导率/规则,因为这第二条规则此规则将激发你的postname模式,所以你永远不会得到这个规则,除非你将其向上之一。

I having a URL http://www.domain.com/postname/?a_different_world

I need to change it to http://www.domain.com/postname/a_different_world

How to remove ? from the URL using Htacccess(Wordpress)

I use following htaccess code. 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 /; also note the ? in the replacement pattern and omission of the QSA flag as you don't want to append the query string.

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.

这篇关于如何删除?从URL使用的htaccess的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆