0

I am trying to change my url using htaccess but it doesn't seem to be working. I want http://example.com/blog_view?id=1 to be changed to http://example.com/blog-id/1/ but it isn't working. I have tried using this.

RewriteEngine On
RewriteRule ^blog-id/([^/]*)/$ /blog_view?id=$1 [L]
Florian Lemaitre
  • 5,905
  • 2
  • 21
  • 44
Henry Okonkwo
  • 363
  • 7
  • 17
  • What URL are you entering in browser and what error are you getting? – anubhava Mar 09 '16 at 11:04
  • Possible duplicate of [URL rewriting with PHP](http://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Henders Mar 09 '16 at 11:18
  • 1
    What does `it isn't working` mean? What happens? I don't understand from your question. Is there an e500 or what? – Al.G. Mar 09 '16 at 11:19

2 Answers2

1

You might have to add a RewriteBase directive:

RewriteEngine On
RewriteBase /
RewriteRule ^blog-id/([^/]*)/$ /blog_view?id=$1 [L]

You can test your rules with this tool

Florian Lemaitre
  • 5,905
  • 2
  • 21
  • 44
  • I just used your code and same thing happened. It still directs to `http://example.com/blog_view?id=1` instead of `http://example.com/blog-id/1/` . I used the htaccess tester and it showed that `RewriteRule ^blog-id/([^/]*)/$ /blog_view?id=$1 [L]` - This rule was not met. – Henry Okonkwo Mar 09 '16 at 12:22
0

You need one redirect and one rewrite rule (already existing):

RewriteEngine On

RewriteCond %{THE_REQUEST} /blog_view\?id=([^\s&]+) [NC]
RewriteRule ^ /blog-id/%1? [R=302,L,NE]

RewriteRule ^blog-id/([^/]+)/?$ blog_view?id=$1 [L,QSA,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643