Reputation: 2268
i was successfully redirected one page and its working fine, but when i am doing the same thing to other pages its not working. what is the best way to redirect and set url using htaccess with out effecting CSS, JS, IMG. bellow is my code which i used to redirect.
RewriteCond $1 ^
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ search.php?loc=$1&q=$2 [L,QSA]
# Redirect to SEO Friendly Url search page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:search\.php)?\?loc=([^\s]+)&q=([^\s]+)? [NC]
RewriteRule ^ /%1/%2? [R=301,L]
#RewriteRule ^([^/]*)/([^/]*)$ /search.php?loc=$1&q=$2 [L]
and my url is
https://www.zesteve.com/search.php?loc=Guntur&q=manjunath-cake-shop
its successfully changed to
https://www.zesteve.com/Guntur/manjunath-cake-shop
i don't to want my url show the page name search.php
now i am trying to change bellow url
https://www.zesteve.com/vendor.php?city=Hyderabad&type=bakers-and-confectioners&vname=manjunath-cake-shop&vid=87411490256961
to
https://www.zesteve.com/Hyderabad/bakers-and-confectioners/manjunath-cake-shop/87411490256961
with the bellow code
# Redirect to SEO Friendly Url Vendor page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:vendor\.php)?\?city=([^\s]+)&type=([^\s]+)&vname=([^\s]+)&vid=([^\s]+)? [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=301,L]
RewriteCond $1 ^
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ vendor.php?city=$1&type=$2&vname=$3&vid=$4 [L,QSA]
its not working am i doing right way?
if any body not understand please leave a comment
Upvotes: 1
Views: 100
Reputation: 785316
In your last rewrite rule you are capturing only one value but using $1,$2,$3,$4
in your target.
Change your rules to this:
# Redirect to SEO Friendly Url Vendor page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:vendor\.php)?\?city=([^\s&]*)&type=([^\s&]*)&vname=([^\s&]*)&vid=([^\s&]*) [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=301,NE,L]
# Redirect to SEO Friendly Url search page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:search\.php)?\?loc=([^\s&]*)&q=([^\s&]*)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ vendor.php?city=$1&type=$2&vname=$3&vid=$4 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ /search.php?loc=$1&q=$2 [L,QSA]
Upvotes: 2