简体   繁体   English

.htaccess重写GET参数

[英].htaccess rewrite GET parameter

I would like to change my URL from site.com/functions/analyze.php?password=test to site.com/functions/analyze/password/test . 我想将我的URL从site.com/functions/analyze.php?password=test更改为site.com/functions/analyze/password/test I am using a .htaccess rewrite rule in attempt to achieve this. 我正在使用.htaccess重写规则来尝试实现此目的。

However, upon browsing to my /functions/analyze/password/test I can see that the GET parameter being passed is test.php/password/test and not test . 但是,浏览到我的/functions/analyze/password/test我可以看到传递的GET参数是test.php/password/test而不是test

Where am I going wrong? 我要去哪里错了?

# Enable editing.
Options -MultiViews
RewriteEngine On

# Hide PHP extenstion.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

# Reroutes for GET.
RewriteRule ^(functions/analyze)/(password)/(.+)$ $1.php?$2=$3 [L,NC,QSA]

You can have this rule in root .htaccess with MultiViews (content negotiation) turned off: 您可以在根.htaccess中关闭MultiViews (内容协商)的情况下使用以下规则:

Options -MultiViews
RewriteEngine On

RewriteRule ^(functions/analyze)/(password)/(.+)$ $1.php?$2=$3 [L,NC,QSA]

or you can try 或者你可以尝试

 RewriteEngine On RewriteRule ^functions/analyze/password/([A-Za-z0-9-]+)/?$ /functions/analyze.php?password=$1 

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

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