Hi, I need help to understand how RewriteCond works
RewriteRule ^([^/]+)/([^/]+) /index1.php?p=$1&NewsID=$2 [NC]
causes the url
to display as
mysite/news/12 (where 12 is a record number)

How can I provide a condition which tests the value of $1
for example
if $1=news then
RewriteRule ^([^/]+)/([^/]+) /index1.php?p=$1&NewsID=$2 [NC]
$1=article then
RewriteRule ^([^/]+)/([^/]+) /index1.php?p=$1&ArticleID=$2 [NC]

if there are less than 2 variables passed the rules are ignored?

Who is Participating?
David S.Connect With a Mentor Commented:
RewriteCond allows you to add conditions based on more than just the path and file name.

It can be used like this:

RewriteCond  %{REQUEST_URI} ^news/ [NC]
RewriteRule ^([^/]+)/([^/]+)? /index1.php?p=$1&NewsID=$2

RewriteCond  %{REQUEST_URI} ^article/ [NC]
RewriteRule ^([^/]+)/([^/]+)? /index1.php?p=$1&ArticleID=$2

However, in this case it seems that you don't really need it. This is a shorter alternative:

RewriteRule ^news(/([^/]+))? /index1.php?p=news&NewsID=$2 [NC]

RewriteRule ^article(/([^/]+))? /index1.php?p=article&ArticleID=$2 [NC]

> if there are less than 2 variables passed the rules are ignored?

That's because the second matching group was not set as optional. You can add a question mark after its right-parenthesis to make it optional.
joomlaAuthor Commented:
thanks for the wonderful examples.
i successfully tested the 'shorter alternative'.... thank you.

In terms of the second questions
I tried
RewriteRule ^newslist(/([^/]+))? /index1.php?p=news_list[NC]
with the expectation that
would give me the desire result.

Can you point out my error
thanks again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.