1

First question, here goes nothing...

I'm trying to add a new entry to my .htaccess file (Apache server) with the hopes of translating this URL:

http://platform.localhost/category.all

into this URL:

http://platform.localhost/index.php?page=category.all

The RewriteRule that I'm currently using is this:

RewriteRule ^([^/\.]+)\/?$ index.php?page=$1

This rule has worked fine for all URLs up until now, I can only assume that it is the period that is breaking it.

What I'm trying to achieve is having anything in the URL after the "http://platform.localhost/" passed into the "page" variable of index.php.

I know I've missed something stupid, can someone please be kind enough to point it out?

Cheers

2 Answers 2

2

the pattern says to reject dots, but you could do tis:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
0
0

Why not just something like:

  RewriteRule index.php - [L]
  RewriteRule (.*) index.php?$1

This might fail because I don't remember exactly if querystrings are included when matching against the pattern, so I'm not sure what would result if you'd request:

http://bla.blub/x?q=1

Also note that this is for a .htaccess/directory context.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.