0

I want to change this URL:

http://example.com/pages.php?sports_id=23

into this:

http://example.com/pages/sports/23

My code is:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php


ErrorDocument 404 /404.php
MrWhite
  • 23,175
  • 4
  • 44
  • 71
Fhd Kaxi
  • 41
  • 4

2 Answers2

0

Add this line to your .htacess

RewriteRule ^pages$ pages.php [L]

But I think it will not be possible to change the GET part to a slash. (Correct me if I am wrong).

0

If you haven't already, you first need to change the URLs in your application to the form /pages/sports/23. You then use .htaccess to rewrite the "pretty" URL back to the real URL.

To literally rewrite /pages/sports/23 back into /pages.php?sports_id=23 then you can do something like:

RewriteRule ^pages/sports/23$ pages.php?sports_id=23 [L]

However, you probably want something more generic. But how generic? It's not clear from your question which elements are variable. Something like the following might work for you...

RewriteRule ^([^/])+/([^/])+/(\d{3})+$ $1.php?$2_id=$3 [L]
MrWhite
  • 23,175
  • 4
  • 44
  • 71