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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:43:33+00:00 2026-05-13T12:43:33+00:00

On my PHP site I would like to sometimes show a maintenance page to

  • 0

On my PHP site I would like to sometimes show a maintenance page to users. I know I can do this in PHP very easily but I would rather use an htaccess file, I think performance may be better this way. So what I am wanting to know is can I modify a htaccess file in PHP? If it is possible I am thinking either,

1 – Have to files and 1 will have the code below in it and the other will not, both files would contain my other htaccess stuff as well. Then php can rename these 2 files when I run an admin script to switch which file is shown, by changing it’s name to .htaccess

2- Read the contents of the current .htaccess file and APPEND the code below into it, then also be able to remove it from the file if needed.

RewriteEngine On
RewriteBase / 
RewriteCond %{REQUEST_URI} !^/maintenance\.php$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

My goal is to build an admin script that can have 1 click processing to change the maintenance page to show or not to show.

Please any sample code or tips on how to do this or if it is even possible to modify a .htaccess file from PHP

  • 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-13T12:43:33+00:00Added an answer on May 13, 2026 at 12:43 pm

    You can use fopen to open and fwrite to write to a file. You’ll want to open it in append mode, read the manual to see which applies.

    That said, this sounds like a strange way to go about doing things.

    I accomplish what you’re trying to do using just rewrite rules that check for file presence:

    RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /maintenance.html [L]
    

    If the maintenance.html file is present, then my site is under maintenance.

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

Sidebar

Related Questions

I would like to pull the share site thumbnail from: http://www.facebook.com/share.php?u=my_website_url inside the tag
I have a simple site to develop and would like to learn PHP as
I have developed a PHP site with PHP 5.3, and would like to deploy
I use MySQL in a fairly complex web site (PHP driven). Ideally, there would
I'm building a PHP site, but for now the only PHP I'm using is
I've got a PHP-based site where we allow users to upload a comma-separated text
Some elements in my page are rendered through php code. Sometimes, on link clicks
We have a modular site and would like to setup searching by module. For
I have seen a feature on a site I would like to emulate. I
I have a site set up complete with an index, etc. I would like

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.