Forum Moderators: phranque

Message Too Old, No Replies

Full URL mod rewrite with .htaccess

.htaccess mod rewrite

         

chriscgorman

12:13 pm on Sep 9, 2007 (gmt 0)

10+ Year Member



Hello,

I am struggling with this one. I am building a CMS and I want the entire contents of the URL put into a variable to be parsed by a PHP page and the correct content displayed. I am putting the rewrite engine in a directory called content. I have worked out this so far:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^.]+)$ /content/index.php?url=$1 [L]

Now the above works for all pages like:

www.domain.com/content/help/faq/first_set/

I will get url=help/faq/first_set/

but if I have a url

www.domain.com/content/help/faq/first_set/?section=2

I will not get the?section=2 put in the url parameter. I will get the same result.

Ideally I would like the url to go in one parameter and anything after the? to go in another parameter, but all in the same parameter would be fine.

chriscgorman

12:35 pm on Sep 9, 2007 (gmt 0)

10+ Year Member



I kind of found the solution:

RewriteRule ^([^.]+)$ /alphacourt/content/index.php?url=$1 [QSA,L]

The QSA will add the parameters to the end and they will be available to query on the PHP page with a $_GET

jdMorgan

1:41 pm on Sep 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[QSA] -- Query String Append -- tells mod_rewrite to append the new query data to the pre-existing query, rather than replacing the existing query string with the new one. So, the effect is the same as what you describe, but it helps to understand the mechanism.

Jim