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

  • SEARCH
  • Home
  • 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 8117287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:06:57+00:00 2026-06-06T04:06:57+00:00

I am trying to use Apache mod_rewrite to achieve the following: In the document

  • 0

I am trying to use Apache mod_rewrite to achieve the following:

In the document root, I have these files (for example):

.htaccess
index.php
dlscript.php

I want /downloads/this_is_path_info to be rewritten to /dlscript.php/this_is_path_info, so:

RewriteRule ^downloads$ downloads/ [R=301,L]
RewriteRule ^downloads/(.*) dlscript.php/$1 [NE,L]

The above does that.

Yet, I want the request to file /dlscript.php returns a HTTP 404 code, so I try:

RewriteRule ^dlscript.php - [R=404,L]

But this also 404 /downloads/. I’ve tried adding RewriteCond %{REQUEST_URI} /dlscript.php, but it seems mod_rewrite replaces %{REQUEST_URI} with the rewritten one.

How could I block direct access to dlscript.php yet enabling the other rewrites?

EDIT:

Thanks to Jon Lin I’ve come up with this idea:

RewriteCond %{REQUEST_URI} ^/dlscript.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /dlscript.php
RewriteRule .* - [R=404,L]

And this worked. The first rule is to prevent problem in ErrorDocument.

But I wonder if this should be considered as a “hack”? Any other appropriate method? Let’s say I also want to ErrorDocument /error.php and makes /error.php returns 404, other methods instead of handling it inside the php script itself?

  • 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-06T04:06:59+00:00Added an answer on June 6, 2026 at 4:06 am

    Try this:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /dlscript.php
    RewriteRule . - [R=404,L]
    

    Matching against %{THE_REQUEST} ensures that you aren’t matching against an internally rewritten URI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP-based web app that I'm trying to apply Apache's mod_rewrite to.
I am trying to use org.apache.commons.collections.CollectionUtils in android with following code import java.util.ArrayList; import
I am trying to make a PHP wiki for my own use, and have
I'm trying to use Apache Lucene for tokenizing, and I am baffled at the
I'm trying to use Apache XMLRPC to manage posts at a small weblog service.
I am trying to use GLSMultipleLinearRegression (from apache commons-math package) for multiple linear regression.
I am trying to figure out how to use Apache Commons IO DirectoryWalker .
I am trying to use MultiValueMap (implementation of MultiMap ) from apache collections. I
I'm trying to use VFS S3 a plugin for the Apache Commons VFS for
I am trying to download an image from URL. I use the Apache Commons

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.