homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod rewrite for query string
rewrite, not not redirect
Patrick Taylor

WebmasterWorld Senior Member 10+ Year Member

Msg#: 4665253 posted 12:50 pm on Apr 23, 2014 (gmt 0)

I need to get the query string into a .php script.

The context: .htaccess includes as follows:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([A-Za-z0-9_-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_-]+)$ /cms/$1.php [L]


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /folder/([A-Za-z0-9_-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_-]+)$ /folder/cms/$1.php [L]

So, the URL is example.com/page (or example.com/folder/page) and the resource is at example.com/cms/page.php (or example.com/folder/cms/page.php)

Adding parameters to the URL throws up an error so my .htaccess also includes, before the above examples:

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^search(.*)$ /cms/search.php?%1


RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^search(.*)$ /folder/cms/search.php?%1

(search.php is the file that performs a search)

It seems to work, but I've arrived here by reading up plus some trial and error. There seems to be several way of doing this (from reading up) so I am wondering if my rule is efficient and whether I need some sort of flag at the end, eg: [NC,L,QSA].



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4665253 posted 6:52 pm on Apr 23, 2014 (gmt 0)

Aren't you going around in circles? By default, a rewrite or redirect keeps the original query string unless you either replace it with a new one, or end the target in ? meaning "remove the query string". So if you say nothing at all, the original query string will carry over unchanged.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([A-Za-z0-9_-]+)\ HTTP/

This boils down to "There was no query string in the original request", so now I'm confused. Are you trying to keep a query, or add one? There shouldn't be two separate RewriteRules covering the same request.

I think it will work out better if you backtrack and simply explain in English what you're trying to do.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved