mbunch
mbunch

Reputation: 569

AliasMatch: Match on all except if hash

Apache2, Ubuntu, /etc/apache2/sites-available/default.conf

Only number 1 needs to be aliased, number 2 does not. I need an AliasMatch regex that omits any url with ^/#, else passes $1 into the new/path/$1

  1. url.com/some_dir
  2. url.com/#/some_dir

I have tried the following approaches: The first redirects both 1 and 2, because (.*). The second ones does not work at all. The third one doesn't work either, but I was trying to match on alpha-numeric chars as to omit # by default, it also does not work.

AliasMatch "(?i)^/(.*)$" "/new/path/$1"
AliasMatch "(?i)^((?!#).)*$" "/new/path/$1"
AliasMatch "^/[a-zA-Z0-9_-]+$" "/new/path/$1"

How do I omit the url 2 while still allowing url 1 to be Aliased appropriately?

Upvotes: 0

Views: 239

Answers (1)

Laurel
Laurel

Reputation: 6173

Try this regex: ^[^#]+$

Or this one: ^.*?/[^#]+$

They're pretty understandable.

I'm not sure what exactly you're looking to capture, though. You seem to know how to use capture groups, so you could add some. Or, in case you didn't know, if you want EVERYTHING from the regex, you can use $0.

Edit:

Try: ^[^/]*/([^#]+)$

This one will chop off everything after the last slash: ^[^/]*/([^#]+)/[^#/]+$

And this one gets the content between the first and second slash: ^[^/]*/([^#/]+)/

Upvotes: 1

Related Questions