1

i want to write .htaccess to show url with common patters for example

1: abc.com/mypage   --> works fine 
2: abc.com/mypage/page/1  --> works fine 
3: abc.com/mypage/category/2   --> works fine 
4: abc.com/mypage/page/1/category/2   --> not works fine

so below is my .htaccess code

RewriteRule mypage/page/([^/]*) /?p=main_page&page=$1 [L]
RewriteRule mypage/category/([^/]*) /?p=main_page&cid=$1 [L]
RewriteRule mypage/page/([^/]*)/category/([^/]*) /?p=main_page&page=$1&cid=$2 [L]
RewriteRule mypage /?p=main_page [L]

how can we fix it please guide way to fix it

2
  • 2
    Change mypage/page/([^/]*)/categroy/([^/]*) to mypage/page/([^/]*)/category/([^/]*) (miss typed category) Commented Sep 27, 2016 at 21:47
  • no bro that is not issue , i fixed typos in question Commented Sep 27, 2016 at 21:50

1 Answer 1

1

You have a typo but more importantly you are missing anchors in your regex. You can use:

RewriteEngine On

RewriteRule ^mypage/page/([^/]+)/?$ ?p=main_page&page=$1 [L,QSA]
RewriteRule ^mypage/categroy/([^/]+)/?$ ?p=main_page&cid=$1 [L,QSA]
RewriteRule ^mypage/page/([^/]+)/category/([^/]+)/?$ ?p=main_page&page=$1&cid=$2 [L,QSA]
RewriteRule ^mypage/?$ ?p=main_page [L,QSA]
Sign up to request clarification or add additional context in comments.

2 Comments

is that [L,QSA] was missing
QSA is query string append. Did this answer work out?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.