Web Hosting Forum | Lunarpages
News: July 14, 2008 - New Contest! - Submit Your WordPress Theme Designs, Win BIG!
September 1, 2008 - Submit Your Web Site for the Sept 2008 Site of the Month!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 07, 2008, 07:18:49 PM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: Redirect to directory and subdirectory  (Read 45 times)
gueho_fred
Space Explorer
***
Offline Offline

Posts: 6


« on: July 17, 2008, 09:08:04 AM »

In order to redirect one on my domain names to a directory, I use this .htaccess :

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

And it's working fine.

But I have a little problem with the subdirectory "toto" in the directory "test".

When I go to "http://easyfrenchcooking.com/toto/", it's working fine.

But when I go to "http://easyfrenchcooking.com/toto" (no slash at the end of the URL), it goes to the right "toto" directory (which is ok), but the URL is rewrited to : "http://easyfrenchcooking.com/test/toto/" (which is not ok).

I don't want "http://easyfrenchcooking.com/toto" to be rewritten. How can I handle that ?

Another problem : "http://easyfrenchcooking.com/test/" and "http://easyfrenchcooking.com/test/toto/" shoud not work. But the do.
How can I eliminate these URL ?

Thanks for your help.

Fred
« Last Edit: July 17, 2008, 09:18:09 AM by gueho_fred » Logged
MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3266



« Reply #1 on: July 17, 2008, 04:38:13 PM »

There are a number of things going on here that you need to understand. First, I would avoid using "test" as a directory or program or script name. There is a built-in shell command called "test". In a command line environment, it may be invoked instead of the desired program; I'm not sure about the server environment.

RewriteCond conditions are "AND"ed together. You could add a third condition to exclude "toto":

RewriteCond %{REQUEST_URI}  !^toto  [NC]

The "NC" flag says to ignore case, so "toto" is the same as "TOTO". You need to be more careful about your regular expressions: "easyfrenchcooking.com" will match "easyfrenchcooking" followed by any character, followed by "com". If you want to match only  "easyfrenchcooking.com", try

RewriteCond  %{HTTP_HOST}  ^easyfrenchcooking\.com

Note the circumflex (^) to anchor the pattern to the beginning of the line. If you want to match with or without "www.":

RewriteCond  %{HTTP_HOST}  ^(www\.)?easyfrenchcooking\.com

So, in total, to redirect anything except test and toto to test, try

RewriteEngine On
RewriteCond  %{HTTP_HOST}  ^(www\.)?easyfrenchcooking\.com [NC]
RewriteCond  %{REQUEST_URI}  !^test   [NC]
RewriteCond  %{REQUEST_URI}  !^toto   [NC]
RewriteRule  ^(.*)$   /test/$1 


Don't forget that if "easyfrenchcooking.com" is an add-on domain, it will likely show up as "primarydomain.com/easyfrenchcooking/". You would probably then want the RewriteRule to explicitly spell out the domain:

RewriteRule  ^(.*)$  http://easyfrenchcooking.com/test/$1
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM