问题
Im at least 24 hours busy on this subject, I cant seem to get this script to work. The script doesnt redirect at all.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\.skynet\.com$
RewriteRule ^/(.*)$ /mobile/final/$1 [L,NC]
What am I doing wrong?
UPDATE:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\.skynet\.com$
RewriteCond %{REQUEST_URI} !^/mobile/final/
RewriteRule ^(.*)$ /mobile/final/$1 [L,NC]
This partially works, but links like m.skynet.com\download.php wont get redirected
UPDATE: 45min later
Now it suddenly works. But the URL gets rewritten in FireFox, while in Chrome it works properly
UPDATE Seems that the problem with Firefox was caused by a 301-redirect I used earlier, the cache had to be flushed. for it to work properly again
回答1:
Remove leading slash from match:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\.skynet\.com$
RewriteCond %{REQUEST_URI} !^/mobile/final/
RewriteRule ^(.*)$ /mobile/final/$1 [L,NC]
.htaccess
is per directory directive and Apache strips the current directory path (thus leading slash) fromRewriteRule
URI pattern.- You need
RewriteCond %{REQUEST_URI} !^/mobile/final/
to prevent looping.
来源:https://stackoverflow.com/questions/21655889/htaccess-internal-rewrite-from-subdomain-to-subdir-path