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 6855591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:46:41+00:00 2026-05-27T01:46:41+00:00

I am very new to these issues, please help. I have two questions regarding

  • 0

I am very new to these issues, please help.

I have two questions regarding to mod_rewrite (apache 2.2).

1) What I want to do is to for example, rewrite /login to login.php. This can be done by

RewriteRule ^/?login/?$ /login.php [L]

However, what I wanted to do too is to disable users to access /login.php directly.

If I just write,

RewriteRule ^/?.*\.php$ /file_not_exist.html [L]

This doesn’t work and even /login will be rewritten to /file_not_exist.html.

Is there any way to do that? I notice that in Apache 2.5 documents, there is an [END] flag but I can’t use it yet in Apache 2.2.

2) I want to replace all ajax request to /ajax/action, the following will do,

RewriteRule ^/?ajax/([a-zA-Z]+)/?$ /ajax/$1.php [L]

However, when I try to access /ajax/xyz where xyz.php doesn’t exist, the browser will show that “/ajax/xyz.php” doesn’t exist, which will make ppl know that /ajax/action is implemented by /ajax/action.php.

How to disable such /ajax/xyz.php doesn’t exist message? The only way I can think of now is to enumerate all files in ajax direction and do the following,

RewriteRule ^/?ajax/(action1|action2|action3)/?$ /ajax/$1.php [L]

Then when user access /ajax/xyz, it will just say /ajax/xyz doesn’t exist but not /ajax/xyz.php. But this is very troublesome. Is there any better way to do that?

Thank you very much!

  • 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-05-27T01:46:41+00:00Added an answer on May 27, 2026 at 1:46 am

    1) If you want to restrict requests for /login.php, you need to use a RewriteCond to check the actual request. Otherwise you’re going to go into a loop.

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /login.php
    RewriteRule ^ /file_not_exist.html [L]
    

    You could also redirect them to /login if you want and let the first rule take care of it:

    RewriteRule ^ /login/ [L,R=301]
    

    2) You can check if an actual file exists before you rewrite the php, again by using RewriteCond and checking using “-f”

    RewriteCond %{REQUEST_URI} ^/ajax/(.+)/?
    RewriteCond %{DOCUMENT_ROOT}/ajax/%1.php !-f
    RewriteRule ^ /ajax/no_action.php [L]
    

    So first we check to make sure the request starts with “/ajax/” and we select the next part “(.+)”. In the next RewriteCond, we use the %1 backreference to access the previous match. So if the request was for “/ajax/blahblah/”, the next RewriteCond would check for “/doc_root/ajax/blahblah.php”. The !-f means “if the file doesn’t exist”. Thus, in this example, if “/doc_root/ajax/blahblah.php” doesn’t exist, then we rewrite the request to “/ajax/no_action.php”. You’d have to replace that with something that you want to handle all of the “bad” requests. Maybe point it to a blank script that simple does nothing so nobody would know the wiser. You can then make a rewrite to change /ajax/(.+)/ to /ajax/$1.php:

    RewriteRule ^ajax/([A-Za-z]+)/?$ /ajax/$1.php [L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I very new to Python, and fairly new to regex. (I have no Perl
I am very new to WCF and SOAP messaging but I have managed to
I am new to Android development. Please excuse me If my question is very
Hi I just want to start by saying I'm very new to LINQ and
I am very new to facebook application development. In my facebook app I want
I'm very new to ASP.net MVC, so please be as descriptive as possible in
I'm new to this forum (at least at asking questions), so please be patient.
Please forgive the newb question. I am very new to .NET so don't assume
I am very new to Ajax technique Is there any site or online documents
I'm very new to Oracle and was wondering if there's a way either through

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.