Forum Moderators: phranque

Message Too Old, No Replies

need help with .htaccess

redirecting

         

RemyXO

4:48 am on Aug 19, 2005 (gmt 0)

10+ Year Member



I tried to redirect with .htaccess but once i did the code below, all my subdomains went with to the redirected url as well. Is there a differnt way around this other then Meta Tags?

//------------start------------------//
redirect /index.php http://www.example.com/forums/
//-------------end------------------//

[edited by: jdMorgan at 5:06 am (utc) on Aug. 19, 2005]
[edit reason] Examplified. [/edit]

jdMorgan

5:05 am on Aug 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, try using mod_rewrite [httpd.apache.org]. You can check for a specific subdomain such as "www" using RewriteCond and the server variable %{HTTP_HOST}, so that the RewriteRule is only applied to that subdomain. You can also check for the main (non-www) domain, if you haven't already redirected it to the www subdomain.

Jim

RemyXO

5:55 am on Aug 19, 2005 (gmt 0)

10+ Year Member


I don't fully understand how this works, im still pretty new to this. I was reading the link you posted and this is what I tried but seems like I have no idea what im doing. :(

RewriteMap %{HTTP_HOST}/index.htm http://domain.com/forums/

RemyXO

6:43 am on Aug 19, 2005 (gmt 0)

10+ Year Member



This is as far as I was able to get. I really dont know what to do to correct this.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/$ /forums/ [L]

jd01

8:41 am on Aug 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you got pretty close.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/$ /forums/ [L]

I would suggest:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [OR]
RewriteRule ^(index\.php)?$ /forums/ [L]

Combined the conditions and made the www optional, so either will qualify for the single rule.

Escaped the special character .(dot) (EG \.) - .(dot) in regex is 'any character except the end of a line'

Cond: Check to see if the accessed domain is www.yoursite.com or yoursite.com - if it is, continue with the rewrite. If not, the condition will fail.

Rule:
Removed / (stripped by Apache before the .htaccess comparrison is made, so nothing will match if it is present.)

Added (index\.php)? - () = group. ? = 0 or 1 of the preceding characters or group of characters. index\.php is the main index, so by grouping and making the group optional, any access to yoursite/ or yoursite/index.php will qualify for the rewrite.

If this is supposed to be an external (seen in the browser) redirect, then adding R=301 to the L flag is necessary. EG [R=301,L]

Hope this helps. You really were very close =)

Justin

RemyXO

10:15 am on Aug 22, 2005 (gmt 0)

10+ Year Member



sorry for the delay in reply, i was away for the weekend.

thank you so much for your help!