Sayan J. Das
Sayan J. Das

Reputation: 922

Weird problem in .htacess occurring after server change

I have a site with 3 scripts, namely viewgames.php, play.php and users.php present at the root directory. I also have a .htaccess file in the same (root) directory.

My .htaccess code that cleans URLs is :-

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^search/(.*)$ ./viewgames.php?search=$1
RewriteRule ^category/(.*)$ ./viewgames.php?cat=$1
RewriteRule ^users/(.*)$ ./users.php?action=$1
RewriteRule ^play/(.*)$ ./play.php?gn=$1
RewriteRule ^([a-z]+)\/?$ $1.php [NC]

ErrorDocument 404 /pagenotfound.php

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

When I was developing in localhost (XAMPP), I got no problem in accessing the clean URLs (using the above htaccess code) such as localhost/MySite/play/foo, localhost/MySite/category/action, localhost/MySite/search/lolol or localhost/MySite/users/myaccount.

It clearly means that the above .htaccess code was working like a charm in my localhost server. Then I uploaded the above code to a shared Apache-based linux server, and encountered some weird problems -

Please check my .htaccess code. I am completely and utterly new to .htaccess, and the above code is merely a copied one. I will really appreciate any help in the matter.

Upvotes: 2

Views: 53

Answers (1)

anubhava
anubhava

Reputation: 785681

Have it like this:

ErrorDocument 404 /pagenotfound.php

Options -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteRule ^search/(.*)$ viewgames.php?search=$1 [L,QSA,NC]
RewriteRule ^category/(.*)$ viewgames.php?cat=$1 [L,QSA,NC]
RewriteRule ^users/(.*)$ users.php?action=$1 [L,QSA,NC]
RewriteRule ^play/(.*)$ play.php?gn=$1 [L,QSA,NC]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+)/?$ $1.php [L,NC]

It is important to keep MultiViews options off to avoid content negotiation feature causing issues for mod_rewrite module.

Upvotes: 4

Related Questions