如何在htaccess的重写规则用,在URL的参数(点或周期)重写、周期、规则、参数

2023-09-02 11:29:15 作者:槿

下面是我的样本网址:

http://mydomain.com/folder/subfolder/index.php?site=www.othersite.com

我要重写这种方式:

http://mydomain.com/folder/subfolder/www.othersite.com

我试图

RewriteEngine on

RewriteBase /folder/subfolder/

RewriteRule ^([A-Za-z0-9\-\.]+)$ index.php?site=$1 [L]

我打印数组$ _GET并返回网站参数为价值'的index.php',它没有返回'www.othersite.com

i printed the array $_GET and returns the value of the 'site' parameter as 'index.php', it didn't return 'www.othersite.com'

如何才能做到这一点?

感谢

推荐答案

在你的.htaccess文件试试这个规则:

Try this rule in your .htaccess file:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} !^site= [NC]
RewriteRule ^(folder/subfolder)/(.*)$ /$1/index.php?site=$2 [L,NC,QSA]