简体   繁体   English

尝试重写.htaccess中的网址,但不更改

[英]Trying to rewrite url in .htaccess but not changing

I am trying to rewrite my URL http://localhost/jainvidhya/register.php?role=admin to http://localhost/jainvidhya/register/admin , but the following code doesn't work: 我试图将我的URL http://localhost/jainvidhya/register.php?role = admin重写为http:// localhost / jainvidhya / register / admin ,但是以下代码不起作用:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.localhost [NC]
RewriteRule ^(.*)$ http://localhost/jainvidhya/$1 [L,R=301]

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^register/(.*)/$ register.php?role=$1&%1

I have also tried restarting my server and clearing browsing history 我也尝试过重新启动服务器并清除浏览历史记录

So first you can either drop the RewriteBase / or set it to the jainvidhya subdir. 因此,首先您可以删除RewriteBase /或将其设置为jainvidhya子目录

RewriteBase /jainvidhya

Also the last RewriteRule tries to match an ending / (slash) sign in the URL, so you may want to put that optional like this: 另外,最后一个RewriteRule会尝试匹配URL中的结尾符号(/)(斜杠),因此您可能希望将其设置为如下所示:

RewriteRule ^register/(.*)/?$ register.php?role=$1&%1

Or better try to specify a proper alphanumeric rexexp like this: 或者最好尝试指定一个适当的字母数字rexexp,如下所示:

RewriteRule ^register/([^/w]+)/?$ register.php?role=$1&%1

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

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