Maintenance redirect Node.js on Apache - node.js

I'm currently developing some websites with Node.js, but when I take it offline for maintenance etc. it shows me a 503 (an ugly one...)
It's on a host where I can run Node.js on given port (doh) and I need to place an htaccess file with a redirect to that port in the apache folder.
I've been googling a while, and I can't find it... Help?
.htaccess:
RewriteRule ^$ http://127.0.0.1:*portno*/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:*portno*/$1 [P,L]
It's a shared hosting account with SSH access.
Apache Version 2.2.29
cPanel Version 11.48.0 (build 13)

Related

Hide port in address bar when run NodeJS locally on Windows

As we know, when we run NodeJS on hosting server and want to hide port like :3000 from the browser address bar, we can set up ngnix or use in .htaccess the rules like
RewriteEngine On
RewriteRule ^$ http://example.com:3000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://example.com:3000/$1 [P,L]
But what about running NodeJS locally on Windows? Is it possible to hide the port in the browser address bar in this case? I mean without additional server
ps. I run Windows binary 64-bit version of NodeJS on Windows 7

.htaccess routing to Node App

I'm using a shared hosting service that always has Apache web server running, so I can't run my Node.js application directly on port 80. Instead, as I've been told by my host, I need to use .htaccess to redirect incoming requests to my Node.js app, which is currently running on port 50000. Here's the .htaccess file they told me to use:
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:50000 [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:50000/$1 [P,L]
This works well enough, except that when I try to go to mydomain.com, the Node app is seeing a request for /index.php. The tech support for my host seems to be as confused as I am. If I go to mydomain.com/test then Node.js app sees /test, so Apache seems to only be adding index.php on the root URL. Could this be an Apache caching issue from someone accessing the URL prior to the .htaccess file and Node.js app being set up?
UPDATE
At this point, no one seems to have a clue what is going on, so I'm just going to add an 'index.php' route to my Node app. Thanks to everyone who took a look and tried to help out.
You might have DirectoryIndex set up for index.php in apache conf file which may be the reason you are getting index.php automatically, what you can do is to set DirectoryIndex to some filename which may not exist or if it is apache 2.4 use DirectoryIndex disabled in your .htaccess.
This is actually what you are going to want to put in your /public_html directory
In the .htaccess file in the code below you will see
http://127.0.0.1:50000
(50000) is the port you are sending it too. There are 2 spots where you make that update.
Also update the example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
DirectoryIndex disabled
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:50000 / [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:50000 /$1 [P,L]
This is a specific configuration for an apache server with nodejs.

Redirecting another domain to an existing drupal installation's subdirectory

I've been trying to solve a problem for the past few hours. I am desperate for help!
I have two domains:
rd1.example.com/drupal
rd2.example.com
I have a drupal installation in rd1.example.com/drupal/
Further, I started creating content on drupal in a url alias: rd1.example.com/drupal/rd2/
What I want to do is used the second website to point to that specific content within my drupal installation:
rd2.example.com -> rd1.example.com/drupal/rd2/
I don't want it to be a redirect but an internal hidden redirect. The user will think that they are on rd2.example.com.
I've switched rd2.example.com to point to the directory where drupal is installed. I've been trying to edit the rewriterules on drupal's .htaccess but with no luck. Any help is greatly appreciated. Here is my rules so far:
#Existing settings
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^rd2\.example\.com [NC]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
#New rules to accomodate for rd2.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^rd2\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/rd2%{REQUEST_URI} -f
RewriteRule .* /rd2/$0 [L]
Drupal relies on the server variables to process its request. That means when you internally rewrite to /rd2/$0, drupal doesn't know what to do with that. You'll need to reverse proxy *from the rd2` subdomain instead. So leave drupal the way it is, then on the rd2.example.com document root, add:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^rd2 [NC]
RewriteRule ^(.*)$ http://rd1.example.com/drupal/rd2/$1 [L,P]
This will only work if you have mod_proxy loaded on your server, otherwise nothing will happen. Mod_proxy can only be turned on through your server's config. You could also setup the reverse proxy from the vhost config for the rd2 subdomain:
ProxyPass / http://rd1.example.com/drupal/rd2/
Beside of proxy, you may also consider to use a symbolic link that made by a shell command like so:
ln -s /path/to/rd1 /path/to/drupal/rd2
More details is explained in Multi-site - Sharing the same code base

codeigniter block me from accesing my phpmyadmin installation on subdirectory

I have my own CMS built using CodeIgniter (actually, it's not me who developed it. My client gave it to me from their previous developer). No, I'm in the process of migrating the CMS to a new server. I set it up and everything works fine. Except, I can't access my phpmyadmin installation which reside on the subdirectory of my public_html (which contain the CodeIgniter CMS).
www.mysite.com <-- this to access my CodeIgniterCMS based website
www.mysite.com/phpmyadmin <-- this to access my phpmyadmin
installation, which currently inaccessible and just showing CI's
default 404 error page
This might have something to do with CodeIgniter routing configuration or htaccess file and stuff like that. But I'm a total newbie on both CodeIgniter and htaccess.
What should I do to make me able to access my phpmyadmin?
this is my codeigniter htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
let me know what other information (chunk of code, config files etc) should I show here to give better detail of my environment
Your htaccess is not poking a hole through to let access to phpmyadmin.
try
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(phpmyadmin|index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Write an .htaccess file without %{REQUEST_FILENAME}

So I have a ridiculous problem that the hosting company cannot seem to take care of by itself. I have a website on a windows server that has ISAPI Rewrite 3 running to allow me to use .htaccess files for wordpress. But I noticed that the
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
statements are not working. They are just ignored. Is this a configuration issue? In the mean time I have the site up and running with this clever line that I stole from somewhere
RewriteCond %{REQUEST_URI} (/[^.]*|\.(html?|php))$ [NC]
The problem is that using this line I cannot access an actual directory that exists. Ex. /wp-admin/ so if I want to make changes in the admin area I have to enable that line that restricts by IP make the changes and then turn off that line. Utterly ridiculous.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/[^.]*|\.(html?|php))$ [NC]
#disallow or allow just my IP address
#RewriteCond %{REMOTE_HOST} !1.2.3.4
RewriteRule .* /index.php [L]
Any solutions so that I can still access directories that exist without using the %{REQUEST_FILENAME}?
Well .. I have Helicon ISAPI_Rewrite v3 running on IIS 6 (and had it on IIS 7 2 years ago) .. and these instructions actually work fine:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
It may not work that well if part of the URL is virtual folder / application .. but it works fine with real files and folders. Try these instead (should work exactly the same if no virtual stuff involved):
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

Resources