Rewrite rule for nodejs app with subdomain on shared hosting - node.js

I am trying to run a nodejs application on shared hosting and successfully installed node/npm following this tutorial from A2Hosting:
https://www.a2hosting.com/kb/installable-applications/manual-installations/installing-node-js-on-managed-hosting-accounts
I am now on INTEGRATING A NODE.JS APPLICATION WITH THE WEB SERVER part and when I copied the rewrite rules to the .htaccess file, it runs the node on the root domain instead of the wordpress website. Here is my .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN Node
# RewriteRule ^$ http://127.0.0.1:49876/ [P,L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ http://127.0.0.1:49876/$1 [P,L]
# END Node
I wanted the nodejs app to run on the subdomain like: subdomain.domain.com and keep the wordpress running on: domain.com
What changes should I make to the nodejs rewrite rule to make it run on subdomain.

Related

I have a codeignitor website. Which i installed on hosting as www.somedomain.com/folder but it loads base URL :: somedomain.com

I have a codeignitor website. installed in as www.somedomain.com/folder. But when i access this url it redirect to www.somedomain.com
this is my htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\DCV)?$
RewriteRule . index.php$1 [L,QSA]
</IfModule>
Change your config/config.php 'base_url' line to
$config['base_url'] = 'www.somedomain.com/folder';

htaccess rewrite http to https and remove subdirectory from url

Hi I am use Deployer to deploy a Craft CMS website. The site is symlinked to the directory called 'current'. I am using mod rewrite to remove the /current/public from the url in the document root like so:
RewriteEngine On
RewriteCond %{REQUEST_URI} !current/public/
RewriteRule (.*) /current/public/$1 [L]
And inside the current/public folder there is this htaccess to remove the index.php and create nice urls:
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
Edit - Test
The following works to force HTTPS but I end with urls looking like:
example.com/current/public/about etc
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
How can I adjust this to force the site to always use HTTPS?
This will redirected all http request to https.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www.)?yourdomainname.com
RewriteRule ^(.*)$ https://www.yourdomainname.com/$1 [R,L]
Hope this will help you
The following is what I managed to get working:
RewriteEngine on
RewriteRule ^(.*)$ current/public/$1
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

WordPress in Laravel public folder returns 404 not found

I've a laravel installed in /dev.domain.com/ and RootDocument is set to /dev.domain.com/public
The laravel works without any problem and then I install WordPress in newly created directory named "blog" under the laravel's public folder
Wordpress path : /dev.domain.com/public/blog
On localhost I'm can access /blog and setup wordpress as usual, however the problem come with I deploy to live server by cloning with git. The laravel path works fine but when I try to access /blog directory in public folder it returns 404 Not found
Below is the Laravel
/dev.domain.com/public/.htacess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect non ssl to ssl
# and don't redirect subdomain
RewriteCond %{HTTP_HOST} ^dev\.domain\.com [NC]
RewriteRule ^(.*) - [L]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and Wordpress
/dev.domain.com/public/blog/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
# Disable WordPress front-end
RewriteCond %{REQUEST_URI} !/wp-admin
RewriteCond %{REQUEST_URI} !/wp-includes
RewriteCond %{REQUEST_URI} !/wp-login\.php$
RewriteCond %{REQUEST_URI} !/wp-content
RewriteRule (.*) https://www.domain.com/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I've tried to add this one but no chance to make it works
RewriteCond %{REQUEST_URI} !^/blog
Above
RewriteRule (.*) https://www.domain.com/ [R=301,L]
Try this recipe, it works for me.
Add to Laravel .htaccess:
RewriteCond %{REQUEST_URI} !^/blog/ #
And change these lines in Wordpress .htaccess:
RewriteBase /blog/
RewriteRule . /blog/index.php [L]

prevent Q2A redirecting addon domains?

I have the Q2A script installed http://www.question2answer.org/
I have non-www. & non-https redirecting to www & https perfectly but, somewhere within the htaccess code it's redirecting my add-on domain http://addon-domain.com to https://www.main-domain.com/addon-domain.com/
I suspect it's something to do with the following but, have no idea how to edit it correctly:
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Here's the whole code:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# redirect any domain other than www.main-domain.com to www.main-domain.com
RewriteCond %{HTTP_HOST} !^www\.main-domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
# force https on www.main-domain.com
RewriteCond %{HTTPS} ^off
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>

Remove 'web' from Symfony 1.4 path on shared hosting?

I've found a lot of helpful information about installing Symfony 1.4 on a shared hosting plan, but I've run into a stumbling block that's confounded me all day.
Going to http://www.alternium.net/jobeet/index.php returns a 404 instead of the file at http://www.alternium.net/jobeet/web/index.php.
/jobeet/.htaccess:
Options +FollowSymLinks +ExecCGI
# Enable rewrite engine and route requests to framework
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/robots.txt
RewriteRule ^(.*)$ /jobeet/web/robots.txt [L]
# resources
RewriteCond %{REQUEST_URI} ^/images/ [OR]
RewriteCond %{REQUEST_URI} ^/js/ [OR]
RewriteCond %{REQUEST_URI} ^/fonts/ [OR]
RewriteCond %{REQUEST_URI} ^/css/
RewriteRule ^(.*)$ /jobeet/web/$1 [L]
RewriteCond %{REQUEST_URI} !^/jobeet/web/
RewriteCond %{REQUEST_URI} !^/frontend_dev.php
RewriteRule ^(.*)$ /jobeet/web/index.php/$1 [QSA,L]
RewriteCond %{REQUEST_URI} frontend_dev.php
RewriteRule ^$ /jobeet/web/$1 [QSA,L]
/jobeet/web/.htaccess:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} !\.php
#RewriteCond %{REQUEST_URI} !\.php
RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Can anyone with a better understanding than I of Symfony or rewrite rules tell me where I'm going wrong?
If you have a private folder on your shared host (like on plesk hosts) you can put all your symfony folders (expect web/) in your private folder. Then you have to adjust your web dir in the symfony configs and the path to your ProjectConfiguration in your front controller (index.php or frontend_dev.php, ...).

Resources