I'm trying to rewrite the URL using .htaccess
. These all the things I want to do with the rewriting
- Remove the file extension from the URL
- Pass the parameter through URL and GET it in the file
My current .htaccess
the file is as below
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^(.*)$ works?v=$1 [NC,L]
This will rewrite and remove the file extension (http://example.com/file.php
to http://example.com/file
)
I want to send some data (maybe a string) to the page
let's say http://example.com/file2.php?v=something
I want to rewrite it as http://example.com/file2/something
and get the value in the file
I tried the following methods
If I try Method 1 and Method 2 (one after another), it's throwing following error
[Sat Aug 03 12:13:12.881757 2019] [core:alert] [pid 23832:tid 1912] [client ::1:62842] path/to/htaccess/file/.htaccess: RewriteRule: bad flag delimiters
I tried This Method to prevent that error then It threw me below error
[Sat Aug 03 13:14:02.121514 2019] [core:error] [pid 23832:tid 1916] (20023)The given path was above the root path: [client ::1:51899] AH00127: Cannot map GET /path/to/my/file2?v=something.php HTTP/1.1 to file
I think it because .htaccess
is rewriting the value as .php
file.
How can I hide file extension and Get the value at the same time?