Help With Mod_Rewrite

  • Azoundria
  • Professor
  • Professor
  • User avatar
  • Posts: 907
  • Loc: Calgary, Alberta, Canada

Post 3+ Months Ago

Hi All,

I'm trying to convert URLs like this:

http://www.domain.com/some-page?query=this&data=that

To this:

http://www.domain.com/?p=some-page&query=this&data=that

What I am using is this:

Code: [ Select ]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/?([A-Za-z0-9-/]+)\?(.*)$ index.php?p=$1&$2 [L]
  1. RewriteCond %{SCRIPT_FILENAME} !-f
  2. RewriteCond %{SCRIPT_FILENAME} !-d
  3. RewriteRule ^/?([A-Za-z0-9-/]+)\?(.*)$ index.php?p=$1&$2 [L]


This works fine, but it wont pass forward the 'get' data

Code: [ Select ]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule (.*) index.php?p=$1 [L]
  1. RewriteCond %{SCRIPT_FILENAME} !-f
  2. RewriteCond %{SCRIPT_FILENAME} !-d
  3. RewriteRule (.*) index.php?p=$1 [L]


I removed it from .htaccess to prevent it's interference, though ultimately I'd like to be able to handle both cases.

Can someone please explain to me exactly what's going wrong here, and what can be done to make this work?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Any time you add querystring/get variables to your replacement URI it will throw away the querystring from the source URL. Unless you add the QSA (querystring-append) flag where you have your L (last) flag.

Also, RewriteRule removes the querystring from the URI before applying the pattern to the URI.
  • Azoundria
  • Professor
  • Professor
  • User avatar
  • Posts: 907
  • Loc: Calgary, Alberta, Canada

Post 3+ Months Ago

Thanks.

Does anyone know how to make it work then? Is it possible?
  • Azoundria
  • Professor
  • Professor
  • User avatar
  • Posts: 907
  • Loc: Calgary, Alberta, Canada

Post 3+ Months Ago

Bump. Thanks for your help.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

What have you tried since I mentioned the QSA flag ?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Survey says...
  • Azoundria
  • Professor
  • Professor
  • User avatar
  • Posts: 907
  • Loc: Calgary, Alberta, Canada

Post 3+ Months Ago

Okay, I finally figured it out.

Makes perfect sense now, what you said.

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 60 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.