Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert path to query string variable using mod_rewrite

I am trying to make Apache send:
http://mydomain.com/these/are/arguments/mmmk

to:
http://mydomain.com/?pages=these/are/arguments/mmmk

Such that $_GET['pages'] will display these/are/arguments/mmmk.

I have set 'AllowEncodedSlashes' to On.

The rule needs to be able to handle trailing slashes, and when there is no subpages (like http://mydomain.com)

Does anyone know how to accomplish this task?

like image 214
donutdan4114 Avatar asked May 12 '26 20:05

donutdan4114


1 Answers

In order to not rewrite images/scripts you'll need to make sure the file or directory does not exist first in your .htaccess file

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  # Rewrite everything else through the pages parameter 
  RewriteRule ^(.+)$ /?pages=$1 [L] 
like image 158
Mike Almond Avatar answered May 15 '26 09:05

Mike Almond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!