skip to Main Content

I’m trying to modify my website URL for better SEO. Here’s what i have so far:

 RewriteRule ^page-([0-9]+)/?$ /index.php?p=$1 [L,QSA,NC]

i want http://www.domain.com/page-10
instead of http://www.domain.com/index.php?p=10

but how do i also match http://www.domain.com/category/index.php?p=2
and rewrite it to http://www.domain.com/category/page-2

2

Answers


  1. You can another rule for /category/:

    RewriteRule ^(category)/page-(d+)/?$ $1/index.php?p=$1 [L,QSA,NC]
    
    RewriteRule ^page-(d+)/?$ index.php?p=$1 [L,QSA,NC]
    

    You even combine both rules into one with this regex.

    RewriteRule ^(category/)?page-(d+)/?$ $1index.php?p=$2 [L,QSA,NC]
    
    Login or Signup to reply.
  2. Change
    http://www.domain.com/category/index.php?p=2 to
    http://www.domain.com/category/index.php?p=page-2
    and re-write your htaccess to match:

    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^category/([0-9]+)-([a-z]+)  http://www.domain.com/category/index.php?p=$1-$2 [NC]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search