Forum Moderators: phranque
After searching for awhile and not finding a solution, I decided to post.
Maybe I'll just start with an example:
I'm trying to do something like [subdomain.example.com...]
to redirect to [subdomain.example.com...]
(Notice that it's the same subdomain)
So far, I've just managed do this if I redirect to another subdomain (or another domain)
RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/index.php?some_action=$1 [R=301,L]
If I use the same subdomain, it will give me an infinite loop.
Anyone had a similar problem?
Thx in advance.
First, there is nothing in your code to prevent an infinite loop: Requests for "/index.php?some_action=n" will be redirected repeatedly.
Second, it's unlikely you need or want an external redirect, since this will result in the /index.php?some_action URL being listed by search engines, and replacing your static URLs. This is almost never what is desired. It is far more common to use an internal rewrite to pass static URL requests to scripts.
To fix both problems, I'd suggest:
RewriteCond $1 !^index\.php$
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule (.*) /index.php?some_action=$1 [L]
You may also wish to exclude requests for /robots.txt, /w3c/p3p.xml, images, external JavaScript and CSS files, and other "non-scripted" resources.
Jim
I've tried the code you supplied as it makes sense for the application I'm building, but it results in a strange behavior.. As I try to use:
the webpage really slows down (as if it was on a infinite loop) but Apache logs don't show any kind of errors. The .htaccess has only the code you supplied.
Any ideas why the webpage is behaving like this with this code?
Thank you again