skip to Main Content

I want to create SEO urls for my blogs my blog url is like
http://localhost/test/blog.php?blogId=5 i want to convert it to blogs title.

I am currently trying this in .htaccess page but this didn’t work

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1
RewriteEngine ON
RewriteRule ^([a-zA-Z0-9_-]+)$ blog.php?blogId=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ blog.php?blogId=$1

weird thing is that I tried a similar code for user id’s and it worked.

2

Answers


  1. your URL should be 
    http://localhost/test/1
    
    RewriteRule ^test/([a-zA-Z0-9_-]+)/$ blog.php?blogId=$1 [NC]
    
    Login or Signup to reply.
  2. Try writing it this way…

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 [NC,L] # for user id's no slash
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^([a-zA-Z0-9_-]+)/$ blog.php?blogId=$1 [NC,L] # for blog with slash
    

    A link to a userid would look like /2

    A link to a blog article would look like /2/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search