Weird problem in .htacess occurring after server change

35
February 12, 2019, at 5:50 PM

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 -

  • https://example.com/category/blabla was working fine, and so was https://example.com/search/blabla
  • But the URLs https://example.com/play/xyz and https://example.com/users/anyaction stopped working. By that I mean, the page was loading fine, the site was there, but no $_GET values were passed to the PHP script. Thus, I am not able to get the value of parametes gn and action. (see above code)
  • I even tried by var_dump-ing the $_GET array in the scripts, and they returned an empty array, meaning that no values were sent to the script.

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.

Answer 1

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.

READ ALSO
I want to create a delete button for date ,start time and end time but not getting how to do it

I want to create a delete button for date ,start time and end time but not getting how to do it

// I tried to do it but it didn't workI tried using echo statement but it didn't work as well

64
Office365 standalone php app authorization

Office365 standalone php app authorization

I have a standalone PHP webapp that I am tasked with adding Office365 authorization to in order for only authorized users to access

44
pdf to byte array conversion in php

pdf to byte array conversion in php

I need to convert Pdf file to byte array conversion in phpI am looking for like this result

52
Need help getting index or identifier to use it as an unique key from JSON object without converting it to an array

Need help getting index or identifier to use it as an unique key from JSON object without converting it to an array

i'm provided with a JSON object and i can output the values as i want to, but i also want to use the numbers (83 & 167 generated randomly) as shown in the code as an unique identifier, but i can't seem to get only the numbers, can someone point me in the right direction?

53