tags:

views:

34

answers:

2

I want to make a static copy of a site, retaining existing URLs. The problem is that the URLs looked like:

http://mysite/index.php?id=XXX

and Apache does not want to find the file "index.php?id=XXX". Instead, it interprets the request as the file "index.php" with the query "id=XXX".

How can I ask Apache to stop handling the question mark?


Finally, my solution:

1) rename the files from "index.php?id=XXX" to "index.php_id=XXX"

2) Add to .htaccess:

RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteCond %{QUERY_STRING} !=""
RewriteRule ^(.*)$ $1_%{QUERY_STRING} [L]
+5  A: 

Escape the ? as %3f: http://www.example.com/index.php%3fid=XXX.

If you list the file in a directory that has indexes on, Apache will correctly generate links of this format. You must, however, rewrite the links in the existing pages.

jleedev
+1  A: 

You cannot ask a web server to stop adhering to the http protocol.

klausbyskov
Sure you can. `RewriteCond %{QUERY_STRING} !^$` `RewriteRule ^(.*)$ %{DOCUMENT_ROOT}$1?%{QUERY_STRING} [NE]`.
cHao