0

I have been using this rewrite rules for few months and had no problem. Recently there have been an issue with the servers and the localhost with these rules.

I get a 404 error when access pages without .php or .html extensions. I tried few answers which was provided online but nothing helped me in this problem. The 404 error redirects to http://example.com/error.html as written in the htaccess.

 RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.example\.com$ RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L] RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L,QSA] ErrorDocument 403 http://example.com/error.html ErrorDocument 404 http://example.com/error.html <IfModule mod_deflate.c> # Compress HTML, CSS, JavaScript, Text, XML and fonts AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml # Remove browser bugs (only needed for really old browsers) 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 </IfModule> ## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType text/css "access plus 1 month" ExpiresByType application/pdf "access plus 1 month" ExpiresByType text/x-javascript "access plus 1 month" ExpiresByType application/x-shockwave-flash "access plus 1 month" ExpiresByType image/x-icon "access plus 1 year" ExpiresDefault "access plus 2 days" </IfModule> ## EXPIRES CACHING ## Options +FollowSymLinks RewriteEngine on RewriteRule example.php/(.*) example.php?p=$1 Options +FollowSymLinks RewriteEngine on RewriteRule example.php/(.*) example.php?id=$1 

1 Answer 1

1

How about adding the following code?

Options +FollowSymlinks +MultiViews -Indexes IndexIgnore * 

And also why would you have redundant code at the end:

 ## No extension Options +FollowSymLinks RewriteEngine on RewriteRule example.php/(.*) example.php?p=$1 ## Control File and folder conflict RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l 
Sign up to request clarification or add additional context in comments.

2 Comments

Do you know why you have RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L,QSA]? Delete those and try replace with RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l? Make sure you backup though. When you try again, make sure you delete the reduntant code, and temporarily remove the codes from line 5-7
Yes, to redirect index -> index.php and aboutus -> aboutus.php for uses for those I added them. Was working fine but I did not change any but the issues came up recently. I tried those 2 lines, still the same

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.