Page 1 of 1

Apache modrewrite URL to simply remove ? from URL?

Posted: Thu Feb 05, 2009 11:51 pm
by JAB Creations
All I'd like to do is redirect or modrewrite or whatever this...

http://localhost/Version%202.9.A.3/blog ... stallation

...to this...
http://localhost/Version%202.9.A.3/blog ... stallation

I'm using XAMPP on XP (if that matters at all) have have uncommented mod_rewrite.

I've tried a few various scripts though Apache is just insanely rigid. 8O

A little help please?

Re: Apache modrewrite URL to simply remove ? from URL?

Posted: Fri Feb 06, 2009 12:28 am
by JAB Creations
This seems to work!

Code: Select all

<ifmodule mod_rewrite.c>
  RewriteEngine on      
 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ blog/index.php?q=$1 [L]
</ifmodule>
...and to access the query try the following...

Code: Select all

echo '<div>'.$_SERVER['argv'][0].'</div>';

Re: Apache modrewrite URL to simply remove ? from URL?

Posted: Sat Feb 07, 2009 2:38 am
by JAB Creations
I saw a video (thanks for the link Josh) and tried out some code...it's minimal and allows exceptions for file extensions so I thought this would be a helpful revision of the code I've posted...

Code: Select all

<ifmodule mod_rewrite.c>
  RewriteEngine on
  RewriteRule !\.(css|gif|jpg|js|png)$ page.php
</ifmodule>
*EDIT* Removed "?q=$1" from the end of line 3. Archive readers may want to change page.php to index.php after they become comfortable with this.