Forum Moderators: phranque

Message Too Old, No Replies

big problem with mod_rewrite RewriteRule

i'm trying to make a dynamic page point to a static one

         

gilahacker

12:15 am on Oct 1, 2004 (gmt 0)

10+ Year Member



Ok, I've got URL's that look like this:

http://www.example.com/?page=confidentiality&id=12345

And they need to look like this:

http://www.example.com/confidentiality.html?id=12345

I tried this:

RewriteRule ^?page=confidentiality$ confidentiality.html

but got this on all my pages:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

--------------------------------------------------------------------------------

Apache/1.3.31 Server at www.example.com Port 80

as I (obviously) have no idea what I'm doing, I am in need of some real help here...

I checked here:

[httpd.apache.org ]

but it didn't seem to have quite what I was looking for.

My reason for doing this is that I've just recently re-vamped my site and it no longer uses "?page=", just static pages (created dynamically in the background) but I've got several customers who have already recieved emails with the "?page=confidentiality" link in them.

I'm also not sure how to maintain the id during the rewrite... it's got to go from "&id=12345" to "?id=12345" and not get lost along the way.

Anybody got any ideas?

Thanks for any and all help in advance.

-JL

*all instances of my website have been replaced with "www.example.com" as they mess with the url's anyways

[edited by: jdMorgan at 12:48 am (utc) on Oct. 1, 2004]
[edit reason] Removed specifics per TOS [/edit]

gilahacker

12:23 am on Oct 1, 2004 (gmt 0)

10+ Year Member



I'd also like to mention the fact that I have access to the ".htaccess" file but I don't know if I can get into all of the server stuff per se.

Maybe I'm going about this the wrong way...

I'm thinking maybe instead of a mod_rewrite that maybe I could add some php code to the top of my home page (which is what loads if I have http://www.example/?page=confidentiality) that would detect the page variable and kick the visitor to the correct page...

I'm going to have to play with that maybe.

[edited by: jdMorgan at 12:45 am (utc) on Oct. 1, 2004]
[edit reason] Removed specifics per TOS [/edit]

jdMorgan

12:44 am on Oct 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In order to test and manipulate the query string, you'll need to use RewriteCond [httpd.apache.org]:

RewriteCond %{QUERY_STRING} page=(.+)&id=(.+)
RewriteRule ^$ /%1.html?id=%2 [L]

As written, this will only work if the requested page is "/" and the code is placed in .htaccess
It can be modified to handle other pages as well, but then you'll also need to add a RewriteCond to exclude rewriting your custom error pages.

Jim

gilahacker

6:04 am on Oct 1, 2004 (gmt 0)

10+ Year Member



Jim,

Your nick sounds familiar, perhaps you've helped me out before... either way YOU ARE A GENIUS!

THANK YOU SO MUCH!

Worked like a charm!

Thanks Again,

-JL