Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

URL rewriting in htaccess. Remove id and title in the url

php .htaccess

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 keanallen


    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 22 June 2016 - 04:38 AM

Hi I want to change my current url which is like this:




Here is my current htaccess code

RewriteEngine on

#1) remove .php extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

#2) Externally redirect from "/library/this-book?bookid=foo&_title=bar" to "/library/this-book/foo/bar"

RewriteCond %{THE_REQUEST} /library/this-book\?bookid=([^&]+)&_title=([^\s&]+) [NC]

RewriteRule ^ /library/this-book/%1/%2? [NC,L,R]

#3) internally map "/library/this-book/foo/bar" back to "/library/this-book?bookid=foo&_title=bar"

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^library/this-book/([^/]+)/([^/]+)/?$ /library/this-book?bookid=$1&_title=$2 [NC,L]

The code gives the exact result that I want. But it gives me an error saying "object not found". I think there was something wrong in internal mapping of data. Anyone can helpme please???


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download