Forum Moderators: phranque

Message Too Old, No Replies

rewrite with optional characters

         

smallcompany

1:11 am on Dec 26, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,

I have URLs to rewrite in this fashion:

RewriteRule ^name1-123-name2/ http://www.example.com/aa-bb/ [R=301,L,NC]
RewriteRule ^name1-name2/ http://www.example.com/aa-bb/ [R=301,L,NC]

How do I put that 123- part so it counted if there, but ignored if not?

I would like to have a single line like this:

RewriteRule ^name1-(123-)name2/ http://www.example.com/aa-bb/ [R=301,L,NC]

For example, I know a question mark is used to mark a character that may or may not be there (in PHP scripts), like in this example:

https? which means it can be both http or https.

How do I do this in .htaccess for that 123- part?

Thank you and Happy Holidays!

lucy24

1:23 am on Dec 26, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Parentheses. (May be called “round brackets” in the UK.)

smallcompany

2:36 am on Dec 26, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks.

Looks like I got it by adding the "?" to my example, just as I had it in PHP sample:

RewriteRule ^name1-(123-)?name2/ http://www.example.com/aa-bb/ [R=301,L,NC]

Thank you