.htaccess从网址中删除问号 [英] .htaccess remove question mark from url
本文介绍了.htaccess从网址中删除问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网站,该网站的URL中有一个我要重写的查询字符串.网址是domain.com/profile.php?user=sven
,我希望它重定向到domain.com/profile/user/sven
.
I have a website that has an query string in the url that I want to rewrite. The url is domain.com/profile.php?user=sven
and I want it to redirect to domain.com/profile/user/sven
.
我创建了一个具有以下规则的htaccess文件:
I have created a htaccess file that has the following rules:
RewriteEngine On
RewriteRule ^/?user/([^/]+)/?$ profile.php?user=$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^user=([A-Za-z0-9\-\_]+)$
RewriteRule ^profile\.php$ domain.com/user/%1?/ [L,R=301]
这有效,但是重定向到的网址是:domain.com/user/sven?/
This works but the url it redirects to is: domain.com/user/sven?/
我的问题是,我可以删除网址中的?
吗?
My question is, can I remove the ?
in the url?
推荐答案
将您的htaccess更新为以下内容,
Update your htaccess to following,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?profile/(.*?)/?$ /profile.php?user=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profile\.php\?user=([^]+)
RewriteRule ^/?profile\.php$ /users/%1? [L,R=301]
</IfModule>
我希望这会有所帮助.
这篇关于.htaccess从网址中删除问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文