apache configure site maintainance page - apache

I am trying to configure in apache httpd.conf for the below scenario. Can anyone please advise how to do it.
When the apache instance is up and some one tries to hit below url
http://mydomain.com/xxx
It should display content exists in sitemaintenance.html without changing url context path.
Assume sitemaintenance.html resides in /usr/local/apache/my-apache-instance/htdocs/sitemaintenance.html
Here xxx is a subdomain which is hosted separately from main domain (mydomain.com).
-KS

Try placing this into httpd.conf or .htaccess for your sub-domain:
RewriteEngine on
RewriteCond /usr/local/apache/my-apache-instance/htdocs/sitemaintenance.html -f
RewriteRule ^.*$ /sitemaintenance.html [PT,L]
The condition in RewriteCond enables rewrite only if that file exists, so you can dynamically add or delete it, without re-starting Apache or changing .htaccess.

Related

htaccess Remove directory from end of URL in apache

Ok, so I know this is a question that has been asked many times, however, I have not been able to find an answer to my particular case, so please do not shoot me down.
I have a website: http://gmcomputers.co.za.
I am redirecting this URL, using .htaccess file, to a subfolder to load the content:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /gmcomputers/ [L,DPI,R=301]
Which works perefectly, except when I go to http://gmcomputers.co.za I get http://gmcomputers.co.za/gmcomputers/.
So my question is, how do I modify the above code to remove the /gmcomputers/ from being appended?
Please note I copied the code above from a website as I am not at all experienced in redirect, etc and am still learning. Also, the reason I am using .htaccess to redirect is due to there being other websites in the root directory and I therefore cannot edit any config files for Apache.
Thanking you.
You contradict yourself in your question. On the one hand you write that you want to redirect and that this "works perfectly", but then you write that you do not want that result.
My guess is that you actually do not want to redirect at all, but that instead you want to internally rewrite your requests to point to that server side folder. While the URL visible in the browser's URL bar does not show that folder. Is that what you are trying to ask?
If so take a look at this example:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/gmcomputers
RewriteRule ^ /gmcomputers%{REQUEST_URI} [END]
You might want to add an actual redirection to direct clients actually using the folder name in their requests:
RewriteEngine on
RewriteRule ^/?gmcomputers/(.*)$ /$1 [R=301,END]
RewriteCond %{REQUEST_URI} !^/gmcomputers
RewriteRule ^ /gmcomputers%{REQUEST_URI} [END]
Best is to implement such rules in the central http server's host configuration. If you do not have access to that you can instead use a distributed configuration file (typically called ".htaccess") located in the DOCUMENT_ROOT folder configured for the http host, if you enabled the consideration of such files in your host configuration . Though that comes with a number of disadvantages. Above implementation works likewise for both approaches.

My homepage wont go through HTTPS port

So my domain is [1] and as you can see whenever you go on that link it will get HTTP (without padlock) but if you go to any other link it will be HTTPS. Only my homepage goes through HTTP.
Important things to mention is that I use Apache.
Every my attempt to edit .htaccess file ends up by website stoping to work. My whole website is hosted on AWS and that is where I derived my SSL certificate.
I want to make that homepage load in HTTPS as well.
How should I do that?
Here is my app folder and place where I created my .htaccess file.
[1]:
Adding this to your .htaccess should do it:
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule ^$ https://www.urtina.com/ [L,R=301]
If it breaks Apache, check the error log. It is for the homepage only as requested.

Apache web server: URLs that contain a "." results in "Permission denied"

We are trying to migrate traffic from our old Netsuite store to a newer solution. The last step before launch is configuring the .htaccess file to redirect traffic from the old Netsuite URLs to the new SEF URLs.
Netsuite URL:
www.myoldstore.com/s.nl/sc.27/.f
New URL:
www.mynewstore.com/store-home-page
For launch, we will point the old domain "www.myoldstore.com" at our new server which is configured to accept traffic for this domain.
I configured the following .htaccess rules:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.myoldstore\.com [NC]
RewriteRule ^ https://www.mynewstore.com/store-home-page [L,R=301]
However, I just discovered that any traffic on our server (Apache 2) that has a path like the old Netsuite URL (/s.nl/sc.27/.f) generates a "Permission denied" message.
Is there some way to configure either the server or .htaccess to allow/handle paths like that?
UPDATE: I found the problem. The new site is a Drupal site, and Drupal's default .htaccess file includees the following rule:
RewriteRule "(^|/)\." - [F]
That is intended to block access to hidden directories. I didn't want to remove it altogether, so I moved it lower in the .htaccess file so it only processes after the specific old URLs have been handled.
The new site is a Drupal site, and Drupal's default .htaccess file includes the following rule:
RewriteRule "(^|/)\." - [F]
That is intended to block access to hidden directories. I didn't want to remove it altogether, so I moved it lower in the .htaccess file so it only processes after the specific old URLs have been handled.

htaccess redirect domain and mask url

I want to redirect a domain name : http://www.newdomain.com to http://sub.maindomain.com
I have edited .htaccess as:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !sub.maindomain.com$ [NC]
RewriteRule ^(.*)$ http://sub.maindomain.com/$1 [L,R=301]
It redirects but the http://sub.maindomain.com visible in the address bar . Help! How to do the masking so that http://www.newdomain.com would be visible . Thanks
And also I want create a subsite http://sub.newdomain.com . How to do it with .htaccess .
If www.newdomain.com and sub.maindomain.com are on different hosts, the only way to get the content on sub.maindomain.com to be served while the browser's URL address bar says www.newdomain.com is to fetch the content from sub.maindomain.com on behalf of the browser. Since as far as the browser is concerned, it's looking at content on newdomain.
You can do this either by setting up a proxy using apache or maybe a script. Using apache, you'd need access to your vhost config for the www.newdomain.com domain. You can set it up like:
ProxyPassMatch ^(.*)$ http://sub.maindomain.com$1
Take a look at the mod_proxy docs for more info on the flags you can pass this directive, to tweak timeouts and retries.
If you want to setup a php script to proxy, you'll need to route all requests to this php script, so in your htaccess file in your www.newdomain.com document root, add (assuming this php script is called proxy.php):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/proxy.php
RewriteRule ^(.*)$ /proxy.php?url=$1 [L,QSA]
Then in proxy.php, look for the url query string, load that page, and output it to the browser.
Though all of this is much easier if you can just point both domains to the same host.

Rewriting a redirected URL with mod_rewrite

Here is my setup :
I have a website located at www.cabsh.org/drupal
I want to use mod_rewrite to do 2 things :
Redirect www.cabsh.org to http://www.cabsh.org/drupal/index.php (I got this one)
Rewrite /www.cabsh.org/drupal/index.php to www.cabsh.org/site/index.php
I cannot figure how to achieve the 2nd point. I'm using .htaccess files since I cannot use the main server configuration. Can anyone help me getting this to work?
Thanks!
From what I get from your comment, you just want something like this:
RewriteEngine on
# Prevent a request directly to the /drupal folder
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/drupal/
RewriteRule ^drupal/(.*)$ /site/$1 [R=301,L]
# Change a request for /site/(anything) to /drupal/(anything)
RewriteRule ^site/(.*)$ /drupal/$1
Be careful though, since Drupal (being in the Drupal folder) might generate links that point to /drupal instead of /site, which is seemingly not what you want.