Apache Rewrite rules anyone
Author
Discussion

rameshuk

Original Poster:

595 posts

292 months

Wednesday 19th October 2005
quotequote all
Hi all,

I have not written any rules for a while and I'm stuck.

Basically I want users who to try to visit http://mydomainblahblahblah.com
to see http://www.mydomainblahblahblah.com
so basically to insure the www is added if missing.
I'm doing this via a .htaccess file.


I've looked in the manual which gives this example:

RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

now I'm making an error somewhere as it does not work.

any help appreciated.

JamieBeeston

9,294 posts

295 months

Wednesday 19th October 2005
quotequote all
Check your error logs, might simply be that .htaccess / rewrite isnt allowed where you are trying to use it.

Do you get an internal server error, or just nothing?

J

rameshuk

Original Poster:

595 posts

292 months

Wednesday 19th October 2005
quotequote all
mod rewrite is enabled.

.htaccess files work fine.

I've had this problem before and solved it

(Cannot remember what I did though ...it was two years ago)

can you/someone post what it should look like ?

use www.blahsomedomain.com

could it be something simple like spaces ?

thx

JamieBeeston

9,294 posts

295 months

Wednesday 19th October 2005
quotequote all
Check the Error Log, it will tell you why its erroring.

J

TheExcession

11,669 posts

280 months

Wednesday 19th October 2005
quotequote all
^^^^ Wot He said

Silly thing that might be forgotten - I believe the following must be enabled for mod rewrite to work.

Options +FollowSymlinks

You mention that you've enabled rewrite...

RewriteEngine on



rameshuk

Original Poster:

595 posts

292 months

Thursday 20th October 2005
quotequote all
thanks guys - mod rewrite is working
beacuse re-write rules are working (some software on the server uses them).

Basically my current webhost has setup the servername as somedomainname.com
and then used an alias for www.somedomainname.com.

so by default the website uses the domain name without the www. This is problematic because if a user trys accessing say

www.somedomainname.com/cars (not the missing trailing slash) the server sends them to http://somedomainname.com/cars/ . Which can throw javascript /code errors sometimes.
(which is happening now).

If you add the trailing slash at the end , the site displays correctly.

Thats why I'm trying to use Apache rewrite rules to send any requests for somedomainname.com to www.somedomainname.com

*Note: The domain name mentioned is used as an example only. No TLDs were harmed during posting.

:-)