如何使用.htaccess从URL中删除?q = [英] How to remove ?q= from URL using .htaccess
问题描述
我知道 .htaccess
URL重写问题已经问了很多遍了,但是,我真的很难使这两项工作结合在一起。
我的网站使用以下网址并执行通配符搜索
http:// www .localhost:8888 / exercises / exercise?q = overehead%20squat&
我正在使用以下规则删除所有%20
空格给我:
RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \s / +(。*?)(?: \ + |%20 | \s)+(。+?)\sHTTP [NC]
RewriteRule ^ /%1- %2 [L,NE,R = 302]
赠与: http: //www.localhost:8888/exercises/exercise?q=高架蹲
我最后要做的就是删除?q =,因此URL看起来像这样:
http://www.localhost:8888 / exercises / exercise / overehead-squat
小写不是必需的,但这是必需的e。
非常感谢。
创建一个名为 excercise的目录,并将代码文件放入其中(将其命名为 index。 php
),然后放置此 .htaccess
在
上的RewriteEngine RewriteRule ^(。*)index\.php?q = $ 1
I understand that .htaccess
URL re-write questions have been asked a number of times however, I am really struggling to get these two things working in combination.
My site takes the following url and performs a wildcard search
http://www.localhost:8888/exercises/exercise?q=overehead%20squat&
I am using the following rule to remove all the %20
spaces to give me:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R=302]
Gives: http://www.localhost:8888/exercises/exercise?q=Overhead-Squat
The last thing I would like to do is remove the ?q= so the URL looks like this:
http://www.localhost:8888/exercises/exercise/overehead-squat
It is not essential to make it lowercase, however it is desirable.
Many thanks in advance.
Create a directory called "excercise" and place your code file in it (name it index.php
), and place this .htaccess
RewriteEngine On
RewriteRule ^(.*) index\.php?q=$1
这篇关于如何使用.htaccess从URL中删除?q =的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!