当前位置: 动力学知识库 > 问答 > 编程问答 >

.htaccess - Htaccess Rewrite Rule with a PERIOD

问题描述:

I need a rule that when someone types

domain.com/finddomain.com it points to domain.com?q=finddomain.com

Very simple, yet the period in "finddomain.com" is causing my rule to fail.

My rule is:

RewriteRule ^([A-Za-z0-9.]+)(/)?$ index.php?q=$1

The "." screw it up.

Any help is much appreciated!

网友答案:

You have to escape the period with a backslash \. because the period stands for any character.

So your RegEx ^([A-Za-z0-9.]+)(/)?$ does actually match every string.. It should be ^([A-Za-z0-9\.]+)/?$ (or ^([A-Za-z0-9\.]+\.[a-zA-Z]+)/?$ to match only domains with a TLD).

网友答案:

try to escape the dot, since dot in regular expressions denote "anything"

cheers

分享给朋友:
您可能感兴趣的文章:
随机阅读: