charlymz
charlymz

Reputation: 147

Htaccess RewriteRule not passing parameters

I had a Plesk Onyx server, running on Centos 7.2, Apache 2.4 Nginx is OFF, I had the following htaccess

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !(\.js|\.css|\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.ttf|\.woff|\.woff2|\.otf|\.eot|\.ico|\.svg|\.txt|\.xml|\.json)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder1/folder2/([0-9]+)/(.*)[/]$ /folder1/folder2/index.php?get_var=$1 [NC,QSA,L]

The rwwite works OK but its not passing the get_var in index.php I had a var_dump ($_GET) and it is empty if I visit https://sample_domain.com/folder1/folder2/123/

I want to get the 123 value into the get_var tried disabling -MultiViews and no luck

Upvotes: 1

Views: 618

Answers (1)

user2493235
user2493235

Reputation:

That rule can't be working at all for the URL you presented. It would only work for something like:

https://sample_domain.com/folder1/folder2/123//

Or:

https://sample_domain.com/folder1/folder2/123/example/

Try this:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !=/folder1/folder2/index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder1/folder2/([0-9]+)/$ /folder1/folder2/index.php?get_var=$1 [NC,QSA,L]

I removed unnecessary tests since it could only be a directory. And I guess you don't even need that test? Do you have existing directories in /folder1/folder2/ named only with numbers? If not remove that test to improve performance.

Update

To operate this out of a .htaccess file in /folder1/folder2/, change it to be as follows:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ index.php?get_var=$1 [NC,QSA,L]

Upvotes: 1

Related Questions