views:

54

answers:

3

I have a domain let's call it newsite.com which is parked to maindomain.com. I use mod-rewrite to direct all requests for newsite.com to a subdirectory on maindomain.com. On newsite.com I have CodeIgniter installed. Which means the urls look like this:

newsite.com/products/shoes/

The above works just fine.

However, if I set up a controller for a page like this:

newsite.com/about/ or newsite.com/about/faqs/

I get a 404 which I believe is being caused because it is looking for the page maindomain.com/about.php which does exist, but does NOT exist on newsite.com.

My question is.... how do I PREVENT urls like newsite.com/about/ from pointing to newsite.com/about.php ? This is the opposite of what many people try to do (they tend to want to allow the file extension to be missing).

I'm wondering if it is and apache or PHP setting that causes it to look for the file first if it exists and the directory does not? Or do I need to add more mod-rewrite rules?

Thanks very much!

Edit - here is my .htaccess file currently. It resides at the web root of the maindomain.com shared hosting account.

# Redirect various urls to subfolders of the format: /site-thename/

RewriteEngine On

# Remove the www for NewSite.
RewriteCond %{HTTP_HOST} ^www.newsite.com$ [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]

# Handle pages and directories that should not go through CodeIgniter.
RewriteCond %{HTTP_HOST} ^(www\.)?newsite\.com
RewriteCond %{REQUEST_URI} !^/site-newsite/
RewriteCond %{REQUEST_URI} ^/demo/ [OR]
RewriteCond %{REQUEST_URI} ^/robots\.txt [OR]
RewriteCond %{REQUEST_URI} ^/emailform\.php [OR]
RewriteCond %{REQUEST_URI} ^/assets/ [OR]
RewriteCond %{REQUEST_URI} ^/index\.php
Rewriterule ^(.*)$ /site-newsite/$1 [L]


# Handle CodeIgniter URLs.
RewriteCond %{HTTP_HOST} ^(www\.)?newsite\.com
RewriteCond %{REQUEST_URI} !^/site-newsite/
Rewriterule ^(.*)$ /site-newsite/index.php?/$1 [L]
A: 

If you have no rewrite rules for it, Apache, by default, will reference whatever is on the filesystem. You must have rewrite rules there to tell Apache to use a specific controller to handle requests instead of attempting to reference objects on the filesystem.

Andrew Sledge
I found that if I remove my .htaccess file completely, it will still server up about.php when I go to /about/. So... I wonder if this can be a server setting.
Sherri
A: 

I assume that if you are an apache user, you use .htaccess file for redirecting the URL to you 'index' file (let's call it index.php). Also you should have sth like:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

in your .htaccess file. Note that the RewriteCond condition has a parameter which checks if it is not a file:-) More can be found at http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond

Bery
Yes, I'm using Apache and .htaccess for redirection. Full Mod Rewrite rules added above.
Sherri
Try adding the !-f parameter to conditions. It should check whether it is file first.
Bery
I am sorry. I wasn't careful enough when I was reading your question. If I am getting ir right, you try to setup new domain on your host in a subfolder of root (e.g. maindomain)?
Bery
Thanks for your comments Bery. I discovered it was the Apache MultiViews setting that caused it.
Sherri
+1  A: 

Asked my hosting company's support department what might be causing this... and it turns out that it is caused by Apache MultiViews. This can be turned off via

Options -MultiViews

in the htaccess file. That worked. Thanks for the suggestions.

Sherri