Title: short links with htaccess - two arguments
Tags: regex;apache;.htaccess;mod-rewrite
Question: I've got little problem that I am not sure how to fix. I am using htaccess file to rewrite my url to shorter links. For example I am using this rule:

```RewriteEngine On
RewriteRule ^client/(.*)/?$ pages/client.php?action=$1 [L,QSA]
```

but I wanted to also pass second argument to that URL so I made this:

```RewriteRule ^client/(.*)/(.*)/?$ pages/client.php?action=$1&amp;view=$2 [L,QSA]
```

so I could access URL like:

```/client/action_1/view_2
```

without any problems but when I skipped second argument and only accessed:

```/client/action_1/
```

then it was impossilbe and resulted in 404.

How to make a change to that RewriteRule so I can access both:

```/client/action_1/view_2
/client/action_1/
```

and it would rewrite to:

```pages/client.php?action=$1&amp;view=$2
```


Here is the accepted answer: You can have 2 separate rules to handle 2 clean URLs:

```RewriteEngine On

RewriteRule ^client/([^/]+)/?$ pages/client.php?action=$1 [L,QSA,NC]

RewriteRule ^client/([^/]+)/([^/]+)/?$ pages/client.php?action=$1&amp;view=$2 [L,QSA,NC]
```

Comment for this answer: Thank you @anubhava - that is what I needed!
Comment for this answer: I gave you plus 1 for the answer but someone downgraded before your reply so now it's [0]. I am sorry for that but it was not me. Anyway, thank you again!
Comment for this answer: There was a typo, it is fixed now. Please test again.
Comment for this answer: Yes I know it wasn't you. It was from someone who didn't understand the solution. I am seeing many downvotes on my answers without any explanation actually. btw I upvoted your question too.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:05/13/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<regex><apache><.htaccess><mod-rewrite>', 'Title': 'short links with htaccess - two arguments', 'ViewCount': 45, 'id': 30221018, 'user_AboutMe': '', 'user_AccountId': 4033559.0, 'user_DisplayName': 'Cassie Kasandr', 'user_Reputation': 331.0, 'user_Views': 62.0, 'user_id': 3318841.0}}