Search code examples
.htaccessurlrewriting

Url changed but page remains same


I want to change my url

http://www.abc.com/search_result.php?id=110

to

http://www.abc.com/110

Here is the code which i am using.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search_result\.php\?id=([^\s]+) [NC]
RewriteRule ^ http://abc.com/%1? [R=301,L]

But the problem is, url changed to http://www.abc.com/110 , but page remain same.

Please anybody help !

One thing more i want to ask . Suppose i want to add more parameter in original url: Say,

http://www.abc.com/search_result.php?id=110&name=amit

then what i should do to get the result.

http://www.abc.com/i-am-amit

Thanks !


Solution

  • You need an internal rewrite rule also for showing actual content from search_result.php"

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search_result\.php\?id=([^&\s]+)\s [NC]
    RewriteRule ^ http://abc.com/%1? [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$ search_result.php?id=$1 [NC,L,QSA]
    

    Also for http://www.abc.com/search_result.php?id=110&name=amit how do you want pretty URL to be? Keep in mind that you will need both id & name in pretty URL such as:

    http://www.abc.com/110/amit

    Is that how you want?