Welcome to WebmasterWorld Guest from 54.146.180.94

Forum Moderators: Ocean10000 & incrediBILL & phranque

mod rewrite for query string

rewrite, not not redirect

   
12:50 pm on Apr 23, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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]


or

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


or

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].
6:52 pm on Apr 23, 2014 (gmt 0)

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



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.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month