Jonathan Plackett
Jonathan Plackett

Reputation: 2436

mod rewrite regular expressions with a specific length

OK. I have this regular expression in my .htaccess file to rewrite / anything alphanumeric to index.php?id=alphanumeric string.

 RewriteEngine on

 RewriteRule ^([A-Z-a-z0-9]+)$ index.php?id=$1

the problem i'm having is that when some other variables get added to that string, everything stops working.

For example:

www.someaddress.com/ABCDEFGH works fine.

www.someaddress.com/ABCDEFGH&othervariable=123 fails.

I know my alpha numeric string is always 8 characters. is there a way to make the regular expression only match 8 and leave the rest of the string?

Thanks in advance.

Upvotes: 1

Views: 1358

Answers (2)

user1646111
user1646111

Reputation:

try this:

 RewriteRule ^([A-Za-z0-9]{8}) index.php?id=$1

Please note the - character between Z and a is not required

Upvotes: 2

Choker
Choker

Reputation: 975

Something like that should do the trick. You want to remove the $ to let it ignore the rest of the variables.

RewriteRule ^([A-Z-a-z0-9]{8}) index.php?id=$1

Upvotes: 2

Related Questions