Question

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

Was it helpful?

Solution

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) from RewriteRule URI pattern.
  • You need RewriteCond %{REQUEST_URI} !^/mobile/final/ to prevent looping.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top