I am working on a PHP application, in which I need to use forward slash in place of question mark in get request. Like:
www.example.com/article?aid=10&aname=my-article
should be changed to
www.example.com/article/10/my-article
Following is my .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^articles/(.*)$ articles?q=$1 [L,QSA,B]
I have tried a lot, but not able to find solution. How can this can be done?
You can do something like that
RewriteRule ([^/\.]+)/([^/\.]+)/?$ page.php?level1=$1&level2=$2 [L]
The level
then describe your full url separated by the symbol /
Then in the page hypothetically called page.php
you can do:
$firstParameter = $_REQUEST["level1"];
In your case you can do:
RewriteRule article/([^/\.]+)/([^/\.]+)/?$ article?aid=$1&aname=$2 [L]
Then your url will be /article/foo/bar
N.B.
I normally use RewriteBase /
to have the basic rewrite with /
, It is' to put so:
Options +FollowSymLinks
RewriteBase /
RewriteEngine On
You can use this rule to rewrite /article/foo/bar to /article?aid=foo&aname=bar Add the following right bellow RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^article/([^/]*)/([^/]+)/?$ /article?aid=$1&aname=$2 [L,QSA,B]