Reputation: 2674
I need to create a redirect that sends the user to a specified php page with the variable of the page they originally requested, such as:
would send them to
http://website.com/download.php?id=4
However I don't want to redirect them if they request an actual page in the root directory, such as website.com/index.php.
Any idea how to accomplish this?
Upvotes: 0
Views: 155
Reputation: 3053
Should be exactly what you asked for; rewrites the URL to include download.php?id=
unless the request is for any file that physically exists already:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ download.php?id=$1 [L]
Edit: I added the RewriteEngine On
because it may not work without it depending on your server setup. To be fair, mlerley's answer reminded me that it should be there.
Upvotes: 1
Reputation: 70
Assuming Apache 2.2:
RewriteEngine On
RewriteRule ^(\d+)$ /download.php?id=$1
The url doesn't change in this case. This also assumes that your id is always a number.
Upvotes: 1