0

I'd like to use Apache's mod_rewrite in order to treat all dash breaks within a file name as separate folders starting from the top, or vice versa.

For example, if someone was to access /events/booking/?id=1 the file events-booking.php?id=1 would actually be requested.

The current sceript I have is taken from the StackOverflow post below, which simply strips the file of it's extension, but I'd like the addition of the above too.

https://stackoverflow.com/a/1698807/2023781

Any help on how to modify my existing block of mod_rewrite script would be greatly appreciated (I'm not really good with regex yet unfortunately).

Community
  • 1
  • 1
Kemebear
  • 239
  • 1
  • 4
  • 11

1 Answers1

0

Off the top of my head, this should do it:

RewriteRule ^([^/]*)/([^/]*)/$ /$1-$2.php [L]

^ = beginning of path

([^/]*) = match all characters except slash

$ = end of path

$1 and $2 are the two matched strings from the path.

The query string should carry over as-is.

David Ravetti
  • 2,030
  • 1
  • 17
  • 22