Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I probably have this completely wrong:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule .* index.php [L]
#Rewrites so it looks like production
RewriteCond %{REQUEST_URI} !^/Home/
RewriteRule ^(.*)$ /Home/$1 [L]

Can someone set me straight to make all urls http://site/somepage1 , http://site/somepage2, be rewritten as http://site/Home/somepage1, http://site/Home/somepage2. Is there one rule that would capture all of those urls, and prepend '/Home' to all the urls?

Thanks in advance.

Update

Going into httpd.conf and setting 'LogLevel = debug' revealed that the two rules are conflicting:

[Fri Sep 23 10:54:07 2011] [debug] core.c(3065): [client 127.0.0.1] r->uri = /Home/index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php
[Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home

Is there a way to combine these two rewrite rules without this redirection error?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

As simple as this:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/Home/
RewriteRule ^(.*)$ /Home/$1 [L]

Obviously, if you request URL with /Home/ in it directly (e.g. http://site/Home/somepage1, it will not be rewritten to /Home/Home/somepage1 -- so keep this in mind in case you have subfolder named the same as main folder.


UPDATE: Considering new information, lets try this approach:

Options +FollowSymLinks
RewriteEngine On

# rewrite incoming link to /Home/
# but only if it's a non-existing file
RewriteCond %{REQUEST_URI} !^/(Home/|index\.php)
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ /Home/$1 [L]

# route all requests for non-existing resources to /index.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule .* index.php [L]
share|improve this answer
    
Using your example I get 500 error. Here's my .htaccess file. I think my previous ReWriteRules are not playing nice, is there a way that they can both work? Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule .* index.php [L] #Rewrites so it looks like production RewriteCond %{REQUEST_URI} !^/Home/ RewriteRule ^(.*)$ /Home/$1 [L] –  program247365 Sep 23 '11 at 14:03
    
1) Put your current .htaccess into your question (edit it) as your cannot be formatted nicely in comments (as you can see). 2) Check Apache's error log for exact error message -- possibly 2 rules together causing infinite rewrite loop which Apache has to forcibly stop resulting in 500 error. –  LazyOne Sep 23 '11 at 14:14
    
Updated the question with the full .htaccess rules, and added the apache errors I found. Is there a way to get these two rules working together? –  program247365 Sep 23 '11 at 15:16
    
Yes -- it's possible. But for that I need to know what URL is the correct one. For example, what will be the final URL for this request: site.com/somepage1 ? In other words -- how to handle /Home/ and index.php ? –  LazyOne Sep 23 '11 at 15:27
    
Gotcha. I'd like site.com/somepage1 to be site.com/Home/somepage1. And site.com to be site.com/Home. –  program247365 Sep 23 '11 at 15:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.