Forum Moderators: phranque

Message Too Old, No Replies

htaccess issue

         

dan_m40

7:25 pm on Feb 13, 2010 (gmt 0)

10+ Year Member



I need to redirect all request for a domain except request made to a directory on the domain.

Example:
www.my-domain.com (redirect)
www.my-domain.com/form/ (no redirect)

Below is the current mod rewrite directive

RewriteCond %{HTTP_HOST} ^my-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.my-domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.my-other-domain\.com\/$1" [R=301,L]

Any help would be great.
Thanks
Dan

jdMorgan

7:41 pm on Feb 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you trying to exclude the one specific "/form" subdirectory, or *any* subdirectory?

Jim

dan_m40

7:54 pm on Feb 13, 2010 (gmt 0)

10+ Year Member



yes that exactly what I want to do

jdMorgan

8:52 pm on Feb 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Which?

dan_m40

10:41 pm on Feb 13, 2010 (gmt 0)

10+ Year Member



Sorry I misunderstood. I want to setup a directory and use it for data entry but the domain is redirected. I only need access to the one directory.

jdMorgan

11:00 pm on Feb 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteCond %{REQUEST_URI} !^/data-entry-directory-name
RewriteRule ^(.*)$ http://www.other-example.com/$1 [R=301,L]

Note several additional optimizations/corrections to regex patterns, anchoring, and character-escaping.

Jim

dan_m40

6:27 am on Feb 14, 2010 (gmt 0)

10+ Year Member



Thanks Jim it works perfect. I am trying to understand what the code does.

The first line following RewriteCond STRING CONDITION example would mean that "%{HTTP_HOST}" is the environment variable and I am looking for any variations of it with "^(www\.)?example\.com"

The next %{REQUEST_URI} is the incoming URL and I am checking to see if the directory is in it "!^/data-entry-directory-name" I think if it does the it executes the request if not it moves to the next command which redirects to the new server

Thanks again

g1smd

4:04 pm on Feb 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



? means preceding bracketed part is 'optional'.

! means 'not'.

^ means 'begins with'.