0

I want to make

www.example.com/test/ rewrite to www.example.com/example.com/test/  
www.example.com/ rewrite to www.example.com/example.com/  

I can do that with this rewrite configuration:

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

But I also want to redirect the same without trailing slash:

www.example.com/test redirect to www.example.com/example.com/test/  
www.example.com/ redirect to www.example.com/example.com/  

I have tried with this:

RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
RewriteCond %{REQUEST_URI} !^/example.com(.*)
RewriteCond %{REQUEST_URI} !^(.*)/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ $1/ [R=301,L]

but does not work, it redirects to:

IE: http://www.example.com/C:/wamp/www/test/
Firefox: http://www.example.com/C:/wamp/www/example.com/test/

do you know a solution to this (without touching mod-dir conf)?

4 Answers 4

1

I've found the solution:

Options +FollowSymLinks
RewriteEngine On

# Fix missing trailing slashes.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/_l_/example\.com%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ /_l_/example\.com/$1 [QSA,L]

Thanks for your answers.

0

Try

RewriteCond C:/wamp/www%{REQUEST_FILENAME} !-f

or

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f

See also "What's up with REQUEST_FILENAME in mod_rewrite?"

0

I don't know where the "C:" is coming from in your browsers -- a more useful diagnostic would be to find the "Location" header from the HTTP response -- use something like Firebug, LiveHTTPHeaders, or telnet to get that.

Also, given that your second RewriteRule doesn't mention 'example.com' at all, I guess that you have both RewriteRules in your httpd.conf.

If that is the case, then the [L] modifier at the end of your first rule is stopping the second one from executing at all.

0

Why not just use this?

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .