使用Get变量从.htaccess重写URL

时间:2022-10-31 10:51:00

I am working in a project in PHP , I am not using MVC but keeping a single index.php files which changes it's content based on $_GET['module']

我在PHP项目中工作,我没有使用MVC,而是保留一个index.php文件,根据$ _GET ['module']改变它的内容

My current url format is

我目前的网址格式是

http://phpquiz.com/school/index.php?module=user_groups&mid=13&cmid=32

Now i want to change it to

现在我想把它改成

http://phpquiz.com/school/index/user_groups/13/32

I used following script and was able to rewrite url but my site stopped working as it lost get variables.

我使用以下脚本,并能够重写网址,但我的网站停止工作,因为它丢失了获取变量。

 RewriteEngine On

 RewriteCond %{REQUEST_URI} ^/school/index.php [NC]
 RewriteCond %{QUERY_STRING} ^module=(.*)&mid=(.*)&cmid=(.*)
 RewriteRule (.*) http://phpquiz.com/school/%1/%2/%3.asp? [R=301,L]

How can i do this by keeping get vatiables.

我如何通过保持获得可变性来做到这一点。

2 个解决方案

#1


0  

Try this:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/school/index.php [NC]
RewriteCond %{QUERY_STRING} ^module=([^&]+)&mid=([^&]+)&cmid=([^&]+)
RewriteRule ^ http://local.htaccess/school/index.php/%1/%2/%3.asp? [R=301,L]

#2


0  

You seem to be doing reverse. Have this rule:

你好像正在逆转。有这个规则:

RewriteEngine On

RewriteRule ^school/index\.php/([^/]+)/([^/]+)/([^/]+)\.asp$ /school/index.php?module=$1&mid=$2&cmid=$3 [NC,QSA,L]

#1


0  

Try this:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/school/index.php [NC]
RewriteCond %{QUERY_STRING} ^module=([^&]+)&mid=([^&]+)&cmid=([^&]+)
RewriteRule ^ http://local.htaccess/school/index.php/%1/%2/%3.asp? [R=301,L]

#2


0  

You seem to be doing reverse. Have this rule:

你好像正在逆转。有这个规则:

RewriteEngine On

RewriteRule ^school/index\.php/([^/]+)/([^/]+)/([^/]+)\.asp$ /school/index.php?module=$1&mid=$2&cmid=$3 [NC,QSA,L]