user1832464
user1832464

Reputation:

Simple Mod_rewrite RegEx Debug

Apologies for having to ask what seems like a very simple question, but I can't find an answer to this anywhere else.

I have the following .htaccess file with this rewrite rule:

RewriteRule ^project/(.*)/(.*)$ project.php?projectID=$1&pageID=$2

Designed to take a url in the format domain.com/project/10/1 which will redirect and display page 1 of project 10, for example.

The option also exists to just view domain.com/project/10/ without specifying a page number, and if missing it will default to page one.

The problem I have with the RegEx is that this defaulting behaviour requires the trailing slash for the projectID, otherwise it throws a 404.

How can I modify the RegEx so that it doesn't require (but can have optionally) the trailing slash at the end of the example 'domain.com/project/10/' to successfully rewrite to 'project.php?projectID=$1'.

Upvotes: 2

Views: 90

Answers (1)

AnteGemini
AnteGemini

Reputation: 576

You can write

^project/(.*)/?(.*)/?$

Question mark means that preceding symbol is optional

Upvotes: 1

Related Questions