如何防止.htaccess规则重写中的重定向?
这些规则很有效,但我被重定向到:如何防止.htaccess规则重写中的重定向?,.htaccess,.htaccess,这些规则很有效,但我被重定向到: Options +FollowSymLinks -MultiViews RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !www.getshoutbox.com$ [NC] RewriteCond %{HTTP_HOST} ^(.*)\.getshoutbox\.com RewriteRule ^(.*)$ http://www.getshoutbox.com/test.php?id=%1 [L,
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !www.getshoutbox.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.getshoutbox\.com
RewriteRule ^(.*)$ http://www.getshoutbox.com/test.php?id=%1 [L,NC]
如何恢复并保持:
http://www.getshoutbox.com/test.php?id=X
您的规则的问题在于,您使用的是
WWW
的完整域,而不是仅在内部重定向它:
http://X.getshoutbox.com
因为我们已经知道我们不在www.yourdomain.com
或yourdomain.com
,所以捕获子域并使用%1
作为id
传递它,然后删除http://www.getshoutbox.com/
,因为在这种情况下不需要它
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
# do nothing avoid loop
RewriteRule ^test.php$ - [L]
# if domain is not www.yourdomain.com or yourdomain.com
RewriteCond %{HTTP_HOST} !^(www\.)?getshoutbox\.com$ [NC]
# then get the subdomain with ([^\.]+)?\.yourdomain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)?\.getshoutbox\.com$ [NC]
# use the result below
RewriteRule ^ test.php?id=%1 [NC,L]