Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9032693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:02:39+00:00 2026-06-16T08:02:39+00:00

I want use htaccess for two action.there is code RewriteRule ^File-(.+).php$ FileviewerID.php?x=$1 RewriteRule ^File-(.+).php$

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:02:40+00:00Added an answer on June 16, 2026 at 8:02 am

    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, call header() in PHP to redirect to File.php.

    // Fileviewer.php
    // Write to database was successful, redirect to File.php...
    header("Location: http://example.com/File.php");
    exit();
    

    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.

    # Capture both the number and the extension
    RewriteRule ^File-(\d+)\.([A-Za-z]+)$ FileviewerID.php?x=$1&ext=$2
    

    In your PHP FielviewerID.php, process your database action and redirect using the extension as gathered from $_GET['ext'].

    // FileviewerID.php:
    // Store file id in database from $_GET['x'] (hopefully using prepared statements)
    // Then redirect using the file extension from $_GET['ext'], which holds an alphabetic string like "php" or "js"
    
    // Verify that the extension is alphabetic
    // Consider also checking it against an array of acceptable file extensions for 
    // more reliable redirects.
    if (preg_match('/^[a-z]+$/i', $_GET['ext'])) {
      header("Location: http://example.com/File.{$_GET['ext']}");
      exit();
    }
    else {
      // Redirect to some default location for an invalid extension
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use htaccess redirect to a file, but can't get the image
In my root .htaccess file I have the following Wordpress code: RewriteRule ^index\.php$ -
I want use this 1 for using Bar code or QR code scanner. I
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use a single php file to handle all of my voting requests.
I have following in htaccess file: RewriteCond %{HTTP_HOST} ^(www.)?abcdef.com$ RewriteRule (.*)$ http://www.xyz.org.il/$1 [R=301,L] but
Should I use an .htaccess file on a static HTML site? I want to
I want to use .htaccess file to return homepage (index.html) if direct access to
I have some settings which I want to use in .htaccess file. The settings
I want to use htaccess to 301 redirect (not rewrite) urls like: brands.php?brand=Sony to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.