Mod_rewrite and passing $_GET

Hi all,

I’ve had a look in various places but none have a solution that appears to work for me.

I have a sub domain setup (manage.) and to navigate the index.php script pulls the $_GET[‘nav’] from the URL.

I have tried a couple of ways to get rid of the need to see either index.php or it’s URL params…

Basically, instead of seeing either “index.php?nav=pageName” or "/?nav=pageName"
What I would like is to just pass the pageName directly “/pageName” and have the engine pick this up and pass it to index.php.

The last thing I tried was this;
RewriteRule ^/([^/.]+)/?$ /index.php?nav=$1

but all this does is try to navigate to the pageName as if it were a folder, which doesn’t exist…

Any help with what I can do here please?

Depending on the complexity of your system, you could be over-engineering this. You could simply use

Also, I don’t think you need the leading slash. You might find this post helpful in that regard.

Thanks @bobocat,

I’ll have a go when I get back home this afternoon - my webftp doesn’t list my .htaccess file so I can’t download/modify it.

My php application is not too complex, I will want to pass $_POST data to pages eventually, but I thought I’d try and get the basic .com/page to work first.

set it to display hidden files. or use ssh. or edit it via ssh with emacs.

Dreamhost’s Webftp doesn’t appear to have the option xD

Hi again bobocat;

I’ve just now tried that rewrite rule and it gives me an internal server error :frowning:

i didn’t see your reply. you’ll need more than just that single line. it all depends on your requirements. at minimum, you’ll want to prevent an infinite loop which you are probably getting if you use just that line. you can avoid it with:

RewriteCond %{REQUEST_FILENAME} !index.php$
RewriteRule ^(.*) /index.php?nav=$1 [L]

but again, there could be many solutions depending on how your app is set up.

Decided against trying to rewrite the URL - it was becoming a bother and was not really necessary anyway.

But many thanks for all your help @bobocat, it was enlightening to learn something new :slight_smile:

Here’s what works for concrete5 on Dreamhost:

Options +FollowSymLinks

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !^/cgi-bin/.*
# ----- c5 Pretty URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^.*$ index.php/$1 [L]

You may need to use the commented out ^(.)$ rule and comment out the ^. depending on how the software works.