1

This is my entire mod_rewrite condition:

<IfModule mod_rewrite.c>
   <Directory /var/www/>
    Options FollowSymLinks -Multiviews
    AllowOverride None
    Order allow,deny
    allow from all

    RewriteEngine On

    # force www. (also does the IP thing)
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^mysite\.com [NC]
    RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]   
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]

    RewriteCond %{THE_REQUEST} /index\.(php|html)
    RewriteRule (.*)index\.(php|html)(.*)$ /$1$3 [r=301,L]

    RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/sitemap\.xml|/favicon\.ico)
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # Block access to "hidden" directories or files whose names begin with a period. This
    # includes directories used by version control systems such as Subversion or Git.
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]
   </Directory>
</IfModule>

It is suppose to allow only access to mysite.com(/index.php|/assets|/robots.txt|/sitemap.xml|/favicon.ico)

The error was noticed with: mysite.com/sitemap vs mysite.com/sitemap.xml Both of these addresses are resolving to the xml file while the first url should be resolving to mysite.com/index.php/sitemap ***

For some reason mod_rewrite is completely ignoring the lack of an extension. It sounded like a Multiviews problem to me so I disabled Multiviews and it is still going on.

***And then a different rule will eventually take the index.php out, I am having another problem with an extra '/' being left behind when this happens.

This httpd file is setting up for my codeigniter php framework

Answer: Well I found the problem, it turns out that even though I had disabled Multiviews in my httpd.conf file, they were still enabled in the /etc/apache2/sites-available/default and also the /etc/apache2/sites-available/default-ssl

ngl5000
  • 45
  • 1
  • 8

1 Answers1

1

This pair:

RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/sitemap\.xml|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

Treat the two URIs differently. /sitemap.xml does not match the RewriteCond and is passed through to the filesystem. /sitemap does match the RewriteCond and is rewritten to /index.php/sitemap.

The question is: What does your app do with that URI? If it finds the sitemap.xml file and serves it, that would explain the behaviour you are seeing.

I really can't see any way those rewrites could serve /sitemap.xml when the request was /sitemap. One way of verifying whether the request is running through your app or not is to create a new log file and set your app to append to it a line for each request that includes the date, the request URI and what it plans on serving (or what module it's running code from).


You might have to elaborate a little more on the "extra slash" problem and maybe provide some examples. I don't quite understand the question.

With the comments, I understand now that the slash problem is here:

RewriteCond %{THE_REQUEST} /index\.(php|html)
RewriteRule (.*)index\.(php|html)(.*)$ /$1$3 [r=301,L]

To get rid of the extra slash, you simply need to include it with the other part you are stripping out: (index.php):

RewriteCond %{THE_REQUEST} /index\.(php|html)
RewriteRule (.*)index\.(php|html)/(.*)$ /$1$3 [r=301,L]
Ladadadada
  • 25,847
  • 7
  • 57
  • 90
  • The problem is that right now the two URIs are being treated the same. sitemap.xml is simply for search engines, but index.php/sitemap is suppose to end up at the sitemap controller which yields a user friendly sitemap (not xml at all). Instead it is serving up the xml file which is not the function of the controller at all. – ngl5000 Jun 05 '12 at 01:19
  • The slash problem: right now the httpd file above removes all instances of 'index.php' in the url so if you type in mysite.com/index.php/sitemap it will redirect you to mysite.com//sitemap it is pulling out the 'index.php' but i can not get it to take the slash with it for some reason. The httpd file also makes sure that while index.php is visibly removed that it is still the first file that gets accessed. – ngl5000 Jun 05 '12 at 01:22
  • Hey, I actually tried that too but the problem is your matching '/index.php' so if someone enters mysite.com/index.php it wont work because its trying to remove 'index.php/' which is not there. Adding the forward slash before index.php makes it not work at all. – ngl5000 Jun 06 '12 at 17:05
  • And circle gets the square finally!!! I took your approach and just made the forward slash optional - /? - so if there is a slash in front it will take that away too if not it doesnt worry about it. Thank you for your help!! – ngl5000 Jun 06 '12 at 17:09
  • For some reason they wouldn't let me add the ? in so if you could do that to make your answer complete for the next person with a similar problem I would appreciate it – ngl5000 Jun 06 '12 at 21:22