Apache modrewrite URL to simply remove ? from URL?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Apache modrewrite URL to simply remove ? from URL?

Post 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?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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>';
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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.
Post Reply