skip to Main Content

I have a website say ' www.example.com' , I have also created sub domain in this site, say 'www.alpha.example.com'. I need to convert a dynamic page into SEO friendly URL.
My URL is 'www.alpha.example.com/test/article.php?cat=people'

Into

'www.alpha.example.com/test/article/people'

How to solve this using .htacces

Please help me.

2

Answers


  1. Inside DocumentRoot of www.alpha.example.com create a file called .htaccess with this code:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www.)?alpha.example.com$ [NC]
    RewriteRule ^test/article/([^/]+)/?$ test/article.php?cat=$1 [L,NC,QSA]
    
    Login or Signup to reply.
  2. I would do it this way for completeness. This way if they enter www.alpha.example.com/test/article.php?cat=people then it will redirect to
    www.alpha.example.com/test/article/people also so you will be covered both ways.

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www.)?alpha.example.com$ [NC]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /test/article.php?cat=([^& ]+)
    RewriteRule .* /test/article/%1? [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^(www.)?alpha.example.com$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^test/article/([^/]+)/?$ /test/article.php?cat=$1 [NC,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search