views:

30

answers:

1

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 think 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.

+1  A: 

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 /.

John Kugelman
Thanks John. I believe I have added extra complexity here. I am re-writing based on directory name, but in some cases I am also re-writing (via another .htaccess file at my doc root) to map subdomains as folders. I will edit my post to contain this extra information.
Jenkz
I have added the extra information John. For the record, the "simple" (without subdomain mapping) version still didn't pickup the full-stops. I am testing with some even simpler examples to try and confirm my knowledge.
Jenkz
This response answers my original question.
Jenkz