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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:52:37+00:00 2026-06-15T14:52:37+00:00

I rewrite the file name of php files with below htaccess code : ErrorDocument

  • 0

I rewrite the file name of php files with below htaccess code :

ErrorDocument 404 /notfound.html

AddType application/x-httpd-php .cgi
RewriteEngine on 
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [F,L]
RewriteRule ^(.*)\.cgi $1\.php 

What I want to do : can I restrict access to php files too ? for example if visitor want to see page.php get the 404 error and when want to see main.cgi page can see the page without error , is it possible ?
if I can’t do this with just htaccess , what’s the best solution ?

  • 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-15T14:52:38+00:00Added an answer on June 15, 2026 at 2:52 pm

    You could achieve what you want by having the php files outside of your public folder, than have your index.php file include them

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [F,L]
    

    and in index.php something like

    $validFiles = array('page', 'about', 'gallery');
    
    $requestedFile = str_replace('.cgi', '', trim($_SERVER['REQUEST_URI'], '/');
    
    if(in_array($requestedFile, $validFiles ))
    {
        // ../ goes into the parent folder, and code is a sibling of your public folder
        include '../code/'.$requestedFile.'.php';
    }
    else
    {
        // file not found stuff or index here
    }
    

    Though I would question why you need to use the .cgi extension at all, is that something to do with your host, or a legacy requirement? because with htaccess you can have clean urls like

    mydomain.com/products/widget/

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

Sidebar

Related Questions

Possible Duplicate: .htaccess rewrite image file to php script How can I execute a
I'm using a file, page.php, as an HTML container for several content files; i.e.,
I'm trying to create an conditional Rewrite Rule using an .htaccess file and Apache.
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I would like to access a PHP file whose name has UTF-8 characters in
I would like to have one .htaccess file that can rewrite correctly on both
I have this .htaccess that I've been using to rewrite URLs like these: www.example.com/index.php?page=brand
We all know that wordpress have simple .htaccess code like below RewriteEngine on RewriteBase
I have came up with the following rewrite rule that handles the php files
I am attempting to rewrite any URL with _excaped_fragment_=/some/directory to /some/directory?ajax=1. The code below

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.