简体   繁体   中英

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?

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] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM