开发者

Match "full stop" in mod rewrite

At the moment I am just matching numbers, letters, dashes and underscores in my .htaccess file:

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

I also want to match full stops in the string. I don't want to use:

(.*)

I have tried:

([.A-Za-z0-9-_]+)
([\.A-Za-z0-9-_]+)
([\\.A-Za-z0-9-_]+)
([A-Za-z0-9-_\.]+)

None of which seem to work.... how can I escape the full stop so it matches a full stop!

---------- Additional information ----------------

As an example:

mydomain.com/groups/green/ should go to index.php?folder=green

In addition I am also re-writing subdomains over the top of this (I think this is causing the complication)...

anotherdomain.com should map to index.php?folder=anotherdomain.com

I have succesfully re-written the subdomain with the following rule:

# external group domain name
RewriteCond %{ENV:Rewrite-Done} !^Yes$
## exclude requests from myhost.com
RewriteCond %{HTTP_HOST} !^www\.myhost\.com
## allowed list of domain masking domains
RewriteCond %{HTTP_HOST} ^(anotherdomain.com|extra.domain.com|external.otherdomain.com)
RewriteRule (.*) /groups/%1/$1

I thin开发者_JAVA百科k this is where the complication lies.

---------------- Solution ----------------------

Despite not finding a solution to the exact problem above, I have worked around it by changing the first re-direct (which maps the external domains) from:

 RewriteRule (.*) /groups/%1/$1

to:

RewriteRule (.*) /groups/external/$1&external_domain=%1

The second re-write (on the folder) can then interpret the "external domain" variable instead of the folder.


Your first option is the simplest and is correct. Inside square brackets . has no special meaning, so you include it verbatim without any special escaping needed.

Actually there is a small problem with the second dash in 0-9-_. If you want a dash inside square brackets you should place it at the beginning of the character class. Otherwise it will have its special meaning of defining a character range:

([-.A-Za-z0-9_]+)

If that doesn't work there is something else wrong with your RewriteRule. For instance, if this is a global rule rather than per-directory (no RewriteBase) then URLs will begin with a slash /.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜