php - One url with two different paths (url rewriting)


I have a url as following

so it is /file-name/post-name/page-number

so i want the 1st page to display without page number.

and then from second page

My htaccess code is.

RewriteRule post/(.*)/([0-9]+)$ post.php?id=$1&page=$2 [NC,L]

Is there any way to do this? Applicate your help.




You can have 2 rules for this:

Options -MultiViews
RewriteEngine On

# default rule for page #1
RewriteRule post/([\w-]+)/?$ post.php?id=$1&page=1 [NC,L,QSA]

# to handle URLs with specific page #
RewriteRule post/([\w-]+)/(\d+)/?$ post.php?id=$1&page=$2 [NC,L,QSA]

People are also looking for solutions to the problem: php - Filter multidimensional array using multiple rules from another multidimensional array


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.