mim
mim

Reputation: 477

.htaccess rule with expression similar to filename takes to 404 page

The problem is that this simple rule works:

RewriteRule ^about$ aboutus.php [L,NC]

means I can access my site using this url: http://www.example.com/about

But if I change it to this:

RewriteRule ^aboutus$ aboutus.php [L,NC]

then this link does not work: http://www.example.com/aboutus

Means if the rule expression is same as filename, then it does not work.

This rule does work on other servers, but on one particular server it does not work.

The server is: Linux piper 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3+deb7u2 x86_64

PHP Version is: 5.4.34-0+deb7u1

What could be the reason?


Below is the code that comes in the start of the file

# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##


ServerSignature Off
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php

RewriteEngine on
RewriteBase /

after that there are some simple rules

RewriteRule ^abcd/([0-9]*)-[a-zA-Z0-9&\-\+\.\_'"]* abcdef.php?id=$1 [L,NC]

...... some similar rules .......

RewriteRule ^contact$ contactus.php [L,NC]
RewriteRule ^about$ aboutus.php [L,NC]

Now if I change the last rule from ^about$ to ^aboutus$, then it stops working.

Upvotes: 0

Views: 128

Answers (1)

covener
covener

Reputation: 17872

A common cause of this kind of issue is that mod_negotiation (Options +MultiViews) is enabled and doing "similar" mapping. It kicks in when you ask for something with no extension. You can probably disable it with Options -MultiViews and will stop interfering with your explicit rewrites.

Upvotes: 1

Related Questions