Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send get request with forward slash instead of question mark?

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?

like image 550
Vishal Suri Avatar asked Oct 26 '25 08:10

Vishal Suri


1 Answers

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]
like image 128
Amit Verma Avatar answered Oct 28 '25 22:10

Amit Verma