how to create a rewrite rule in htaccess with .(do

2019-08-15 08:16发布

问题:

here is my sample url:

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

i want to rewrite it this way:

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

i tried

RewriteEngine on

RewriteBase /folder/subfolder/

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

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

how can this be done?

thanks,

回答1:

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]