I want use htaccess for two action.there is code
RewriteRule ^File-(.+).php$ FileviewerID.php?x=$1
RewriteRule ^File-(.+).php$ File.php
but this codes can’t run with together
I want send file id to viewer and save it in db then I just want show File.php
for exam user send this file name > http://www.sitename.com/File-256.php
now save 256 in DB and Show File.php, I just want to do that with htaccess.
Mod-rewrite cannot serve files in sequence in this way. Instead it would proceed through the list of rules and if another rule after the first one matched
FileviewerID.php, it would be subsequently rewritten. So while it is possible to use mod_rewrite to match multiple rules on a request, it won’t perform a branching into multiple requests.Really, the proper way to handle this is in your PHP code rather than try to get the web server to do it for you.
Following a successful write to your database in
FileviewerID.php, callheader()in PHP to redirect toFile.php.Update after comments:
To make this work for files other than
.php, you can still use PHP to store in the database and handle the correct redirect, but you would need to retrieve more information from the redirect in Apache. You should capture the file extension as well as the number.In your PHP
FielviewerID.php, process your database action and redirect using the extension as gathered from$_GET['ext'].