简体   繁体   中英

how to redirect with htaccess without changing the URL in browser

I have a normal dynamic url and i want it to make SEO friendly as below

my URL is

domain.com/search.php?v1=mobiles&v2=nokia

to

domain.com/search/mobiles/nokia

please help

You need to use .htaccess file to do this rewriting action without chenging the url in browser, Try the below code

RewriteEngine On  #remove this if already added
RewriteRule ^search/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    search.php?s1=$1&s2=$2    [NC,L] 

I would do this:

RewriteEngine On  #if not already on. 
RewriteCond %{REQUEST_FILENAME} !-f #only if it is not calling a file that actually exists
RewriteCond %{REQUEST_FILENAME} !-d #only if it is not calling a directory that actually exists.
RewriteRule ([a-z0-9]+)(/*)([a-z0-9]*)(/*)([a-z0-9]*)(/*) search.php?v1=$1&v2=$3 [L,NC,QSA]

This will work even if you only go to /mobile/ (assuming your search.php can handle that.)

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM