Diego Vega
Diego Vega

Reputation: 223

Htaccess rewrite condicion url with dash

I'm having trouble to make this htaccess work

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /([temp|ox|cond|new-url]+)/
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)$ graph.php?grap=$1&time=$2 [NC,L]

Before adding new-url condition to the rewrite condition it was working OK

I also tried to put new\-url and new/-url but doesn't work either

What I'm doing wrong?

Upvotes: 0

Views: 1394

Answers (2)

zessx
zessx

Reputation: 68790

I think there are a few errors in your file.

First, ([temp|ox|cond|new-url]+) is the same as ([cdelmnoprtuwx|-]+). Here you're searching for characters, not words. If I understand, you're looking for urls starting by either /temp/, /ox/, /cond/ or new-url. So I would use this condition:

RewriteCond %{REQUEST_URI} ^/(temp|ox|cond|new-url)/

Second, when you match new-url, there's a dash. But your next rule doesn't accept any dash! Change for this one:

RewriteRule ^([a-z-]+)/([a-z-]+)$ graph.php?grap=$1&time=$2 [NC,L]

Notes:

  • I used [a-z] instead of [A-Za-z] as your rule doesn't take case in account ([NC])
  • I added the dash at the end of the character range: [a-z-]

Upvotes: 2

Amit Verma
Amit Verma

Reputation: 41219

I think you need to escape the - inside character class.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /([temp|ox|cond|new\-url]+)/
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)$ graph.php?grap=$1&time=$2 [NC,L]

If that doesnt solve the issue, you can use a simple pattern :

RewriteCond %{REQUEST_URI} /(temp|ox|cond|new-url)/?

Upvotes: 0

Related Questions