Htaccess delete .php and save the query string

Here is my .htaccess file right now.

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [NC,L,QSA] 

This works in that it makes my pages accessible if the .php extension is not used.

 Old = domain.com/test.php New = domain.com/test 

The bad news is that when I send data to the following link, the data is not transmitted. I thought the QSA option did this, but what is the deal?

 domain.com/test?id=1 
+4
source share
3 answers

Matching the entire query string and adding it to the new URL using the backlink should work.

 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)$ $1.php?%1 [NC,L,QSA] 
+5
source

If you pass id you should use this code

 Options +FollowSymLinks RewriteEngine on RewriteRule ^test/(.*)$ /test.php?id=$1 

you can now access

 domain.com/test?id=1 

from

 domain.com/test/1 
0
source

Here's a simpler solution. We use it in our team project. It will work not only in the root, but also in any directory of your site.

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php 
0
source

All Articles