Forum Moderators: phranque

Message Too Old, No Replies

Domains and .htaccess

         

rorax

7:58 pm on May 28, 2003 (gmt 0)

10+ Year Member



I have a problem with my .htaccess file. I'm using this code to redirect users by http_host

RewriteCond %{HTTP_HOST} ^(.*)host.com$
RewriteCond %{REQUEST_URI}!^/directory/
RewriteRule (.*) /directory/$1

everything is ok but if user enters this url - www.host.com/somedirectory (without ending slash) he is redirecting to www.host.com/directory/somedirectory/
Maybe sombody knows what is the reason.

jdMorgan

8:25 pm on May 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



rorax,

Add a rule to fix missing slash in root directory only:


RewriteCond %{REQUEST_URI} !^/
RewriteRule .* / [R=301,L]

RewriteCond %{REQUEST_URI} !^/directory/
RewriteCond %{HTTP_HOST} ^[^\.]\.host\.com
RewriteRule (.*) /directory/$1 [L]

The description of your code does not match what it does though. If you are trying to redirect from [xyz.domain.com...] to [domain.com...] then change the second ruleset to:


RewriteCond %{REQUEST_URI} !^/directory/
RewriteCond %{HTTP_HOST} ^([^\.])\.host\.com
RewriteRule (.*) /%1/$1 [L]

HTH,
Jim

rorax

10:45 pm on May 28, 2003 (gmt 0)

10+ Year Member



Thx for help but I still have the same problem :/
I don't use any subdomains. All I want is redirect www.somedomain.com and somedomain.com to /somedirectory/. I'm affraid that some people will link my directories without ending flash and users will be redirecting to somedomain.com/directory/somedirectory/

RewriteCond %{REQUEST_URI}!^/
RewriteRule .* / [R=301,L]

I think that in my case doesn't work.

Where can I find good .htacces tutorial?

jdMorgan

11:05 pm on May 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



rorax,

Hmmmm... Well, you could also try:


RewriteCond %{REQUEST_URI} ^$
RewriteRule .* / [R=301,L]

Where can I find good .htacces tutorial?

Start here, and follow the links: Introduction to mod_rewrite [webmasterworld.com]

HTH,
Jim

jdMorgan

11:15 pm on May 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



rorax,

I think I misread your first post. Try this instead:


RewriteRule ^directory$ /directory/ [R=301,L]
RewriteCond %{REQUEST_URI} !^/directory/
RewriteCond %{HTTP_HOST} ^[^\.]\.host\.com
RewriteRule (.*) /directory/$1 [L]

Jim