Shubham Verma
Shubham Verma

Reputation: 141

how to remove question mark

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /domain.com/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ /domain.com/$1.php [L]

am using this code for remove question mark but its not working, trying http://domain.com/details?id=71 to http://domain.com/details/id/71 Please help me where am wrong?

Thanks in advance

Upvotes: 0

Views: 230

Answers (3)

Jon Lin
Jon Lin

Reputation: 143896

Your code doesn't do anything remotely close to what you want. Your code simply removes the php extension when a request is made explicitly with the extension and adds it back internally. In order to make http://domain.com/details?id=71 get redirected to http://domain.com/details/id/71, you need:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\s/+([^/]+?)(?:\.php|)\?([^=]+)=([^&\ ]+)
RewriteRule ^ /%1/%2/%3? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$  /$1?$2=$3 [L]

you want this before your rules that remove the php extension

Upvotes: 1

The Blue Dog
The Blue Dog

Reputation: 2475

Assuming your script is called details.php, the following single rule:

RewriteRule details/(.*)/(.*)/$ /details.php?$1=$2

Should rewrite www.domain.com/details/id/71 to www.domain.com/details.php?id=71

You don't need all that other stuff to remove the .php extension.

Upvotes: 0

Phil Perry
Phil Perry

Reputation: 2130

I'm not sure what you're trying to accomplish with the first rewrite, but for the second (the last three lines), if the incoming URI is not an actual directory or file, you want to rewrite something like details/id/71 to /details.php?id=71?

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$  /$1.php?$2=$3 [L]

should get you close, assuming there are always 3 fields. In a RewriteRule you don't put the domain name again.

Upvotes: 1

Related Questions