Skip to content
Advertisement

.htaccess dash in argument

I have the following htaccess rule:

RewriteRule ^listen/([^/]*)-([^/]*)/$ listen.php?pl=$1&id=$2 

Sometimes the second argument (id) has a dash in it and I get 404 Not found, e.g:

mysite.com/listen/something-293Xff4-yZ ( the ID is 293Xff4-yZ)

The issue is that when I’m trying to get the ID argument (using $_GET['id']) – I get only the first part of the ID (before the dash – 293Xff4)

Any idea how I can getthe full part of the ID in this case?

Thanks!

Advertisement

Answer

You may use this regex in RewriteRule:

RewriteRule ^listen/([^-]+)-([^/]+)/?$ listen.php?pl=$1&id=$2 [L,QSA,NC]

It is also recommended to use Options -MultiView at top of your .htaccess as it may cause problems on some Apache versions where it is enabled by default.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement