0

I have url like http://localhost/site/blog.php?id=31 and id is being used on the page blog.php to get the content but i want to show the url like this http://localhost/site/blog/id/31 for seo purpose.It is also fine if url displays like localhost/site/id/31 or any other similar pattern. It is just that code which displays contents is in blog.php and it uses ID parameter to display contents. I have tried following methods but nothing has worked so far. any help from all you experts out there?

RewriteEngine On
RewriteRule ^([^/]+)/?$ site/blog?id=$1 [QSA]

and

RewriteEngine On
RewriteRule ^/?id/([^/]+)/?$ site/blog.php?id=$1 [L,QSA]
Marc B
  • 340,537
  • 37
  • 382
  • 468
Dalip
  • 21
  • 1
  • 5
  • 2
    Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Marc B Oct 04 '16 at 16:46

1 Answers1

0

Try this mate ,

To display :

localhost/site/id/3

Use :

RewriteEngine On
RewriteRule ^site/id/([^/]*)$ /site/blog.php?id=$1 [L,QSA]

To display :

localhost/site/blog/id/31

Use :

RewriteEngine On
RewriteRule ^site/bog/id/([^/]*)$ /site/blog.php?id=$1 [L,QSA]

If this helped you , kindly up vote and tick mark as working

Raja Gopal
  • 1,375
  • 1
  • 11
  • 32
  • Thanks for reply mate i tried both but didn't work. :-( not sure why, any idea? – Dalip Oct 05 '16 at 19:26
  • Thanks for reply mate. I see it shows content with broken css when i enter in the url directly this http://localhost/site/blog/id/31. But what i was expecting is , when i enter this url http://localhost/site/blog.php?id=31 in the browser, it will automatically take me to this one http://localhost/site/blog/id/31 , as it happens in wordpress after changing permalinks. Is it possible? – Dalip Oct 05 '16 at 19:33
  • i tried the same with my localhost but it works for me . can't figure what is blocking over there . few questions 1) Whether you put .htaccess in your main "site" folder 2) Whether you have any other rewrite / redirect in .htaccess 3) If yes , then whether you put this rule on top of that – Raja Gopal Oct 06 '16 at 03:28
  • 1. i am not putting .htaccess in site folder I am putting this in root. 2. I only have above code in .htaccess – Dalip Oct 07 '16 at 18:15
  • @Dalip try putting .htaccess inside /site folder as its where the blog.php exists – Raja Gopal Oct 11 '16 at 04:04