.htaccess rewrite rule ,last query string is append to the url

831 Views Asked by At

Hi i make one cms sites and i need to rewrite my url

current my url is http://www.example.com/index.php?link=pages&cmsid=2&cmsLink=Carpet
it refers the cmsLink
I want my url like http://www.example.com/Carpet
I am using the following code

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^index.php?link=(.*)&cmsid=(.*)&cmsLink=(.*) $3
2

There are 2 best solutions below

0
On BEST ANSWER

To achive this url it not directly possible with .htaccess
I use regular expression and other tings in htacess as well

I put remove the cmsid

current my url is http://www.example.com/index.php?link=pages&cmsLink=Carpet

RewriteCond %{REQUEST_URI} !/admin
RewriteCond %{REQUEST_URI} !^/(.*).php
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?link=pages&cmsLink=$1&%{QUERY_STRING} [L]

it return me http://www.example.com/Carpet

4
On

Try changing your last rule to this:

RewriteRule ^(.+)$ /index.php?link=pages&cmsid=2&cmsLink=$1

Since you want to have url like http://www.example.com/Carpet, so cmsid and link in your url has to be hardcoded to 2 and pages.