Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess rewrite parameters not passing to target page

I want to pass url parameters but parameters are not passing on to the desired page.

Earlier my site was hosted on cpanel and below code works successfully but after I shifted my site to VPS Server with Cent OS Webpanel with Varnish Cache and apache running on server, the parameters are not passed on target page/url.

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  

RewriteRule ^download/(.*).html download.php?q=$1 [L,QSA]

I want to run the url: www.example.com/download/anything.html
and target url after rewrite is www.example.com/download.php?q=anything
The problem is that rewriterule is working but parameters are not passed.

But if I use the below code the parameters are passing Successfully.

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  

RewriteRule ^([a-zA-Z_0-9-]+)$ download.php?q=$1 [L,QSA]

or below code

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*) download.php?q=$1 [L,QSA]

and I am running the below url, the parameters are passed to target page successfully
www.example.com/anything
target url: www.example.com/download.php?q=anything


but I want the URL in the following format www.example.com/download/*****.html replace *Asterisk Sign with actual query.

If I add some static text to the Rewrite url like download/(.*).html the parameters are not passed to target page.

Thanks

like image 579
AmarBunty Avatar asked Dec 14 '25 09:12

AmarBunty


1 Answers

Most likely new server has MultiViews options enabled by default. Place this line on top of .htaccess to disable it:

Options -MultiViews

Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

like image 187
anubhava Avatar answered Dec 15 '25 22:12

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!