openshift default url to redirect to my domain name - openshift

I installed wordpress in an OpenShift free small gear. Excited and trying things out. so my installation can be reached at wpapp-wpapp.rhcloud.com and it works fine. I added another alias there such as mydomain.com (no www in front). Now in my DNS I have my # host name pointing to wpapp-wpapp.rhcloud.com as CNAME and www host name is pointing to mydomain.com (no www in front) as URL Redirect since I want www.mydomain.com to go to mydomain.com. All this is working fine.
The question is when I place in address bar wpapp-wpapp.rhcloud.com it still goes to wpapp-wpapp.rhcloud.com. Can I make wpapp-wpapp.rhcloud.com go to mydomain.com. Is this even possible?
Thank you.

You can do this via .htaccess.
Edit .openshift/config/.htaccess, adding the block starting with "Redirect any host that is...":
RewriteEngine on
# Uncomment the following lines to force HTTPS
#RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Redirect any host that is not example.com to example.com
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://example.com/$1 [L,R]
# WordPress Defaults
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
See the Apache URL Rewriting Guide for more info on .htaccess re-writes.

Related

htaccess , can't access homepage

I'm trying to set locally a project that run on the web on a NGIX server. This is the htaccess i have downloaded:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~sitename/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~sitename/index.php [L]
</IfModule>
I'm trying to run it locally on an Apache server(on mamp) . It have placed the project in a folder on the server root:
http://localhost/sitename/
But i get a blank page.
I can access a specific internal page (and only that one) if i remove the tilde
~
Even without the tilde, i can't access the homepage of the project.
So what i'm doing wrong?
How the tilde works in this context ?
EDIT
my mod_rewrite is loaded/enabled

Restrict access to local address only in the server

I have multiple web application systems in the server and can be accessible through internet using 122.0.0.1 . I want to access one system only in localhost/network without internet connection using 192.0.0.0.
example:
122.0.0.0/abc
122.0.0.0/def
122.0.0.0/ghi
can access through internet. but i dont want to access
122.0.0.0/abc through internet. i want to access it using 196.0.0.0/abc online through LAN.
Is this possible? then how?
Thank you.
In your .htaccess file, you can add these lines to only allow specific ip addresses:
Order Deny,Allow
Deny from all
Allow from YourIPAdress
You could also use this method, include this in your .htaccess or virtual host config file:
Mentioned here: https://stackoverflow.com/a/23325758/1993548
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxy [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxz
RewriteRule .* - [L] #do notthing
#if we are here, the IP is not in the allowed list, redirect
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

Laravel auth/login route not working in server but localhost

I am using laravel 5.4 default authentication system and it is working fine in localhost but when i upload my project to server, it is breaking. when i fill mail and password, it return back me 404 file not found error.
My site url is http://www.happycoder.me/imsRever2.0
You need to configure the .htaccess file as follows:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^imsRever2.0
RewriteRule ^(.*)$ imsRever2.0/$1 [L]
Otherwise, the main web server will not the routing, vs laravel causing the 404 error when the file isn't found.
My htaccess file is below what things i need to change
Options -MultiViews
RewriteEngine On
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

rewrite rule for non.www to https to www.https on .htacces magento

I want to redirect https://example.com to https://www.example.com for my website. Can you help me with the code to put it on .htaccess file. the site is in magento.
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Explained: If the requested host does not start with www., redirect it to start with www
Source|Reference: http://codingbasics.net/magento-htaccess-file-optimized-speed-security-seo/
The link above has a default Magento htaccess file that has been optimized for speed and SEO and has code for rewriting non-www to www, but does not have the code for rewriting HTTPS/SSL non-www to www. So I have grabbed the htaccess code section from the link/site above and made the additional edits to the code below for rewriting HTTPS/SSL non-www to www.
##### Search Engine redirects and rewrites for SEO purposes #####
<IfModule mod_rewrite.c>
# Rewrite|Redirect http to https|SSL & non-www to www
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]
##### Redirect away from /index.php and /home
##### Warning: This index.php rewrite will prevent Magento
##### Connect from working. Simply comment out the
##### following two lines of code when using Connect.
##### Please note - https://www. if not using www simply use https://
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ https://www.yourdomain.com/$1 [R=301,L]
##### Please note - https://www. if not using www simply use https://
redirect 301 /home https://www.yourdomain.com
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>

remove .html extension from url

I'm trying to remove the .html extension from url for my website by editing the .htaccess file under the web root(public_html) directory. My server is bluehost.
The problem is that I have previous settings in the .htaccess file already for the redirecting primary domain to a subdirectory purpose.
The script is below. Also with the script i found online for hiding the extension from url.(The script doesn't work) It will be really nice if someone can help me out with the problem. Thanks.
# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?qinglish.ca$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/qinglish_ca/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /qinglish_ca/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?qinglish.ca$
RewriteRule ^(/)?$ qinglish_ca/index.html [L]
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Instead of your last rule you will need these rules to remove .html extensions fro all URLs:
## hide .html extension
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# To internally forward /dir/file to /dir/file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]
Place them at same place where you have current rule to add .html extension.