URL Mask/Cloak with redirect - regex

Am trying to do the following. My website is hosted on
www.sitehost.com/uk
But I own this domain.
www.mainsite.co.uk
Is it possible to redirect the user hitting www.mainsite.co.uk to www.sitehost.com/uk but retain the www.mainsite.co.uk?
I tried doing .htaccess redirect and it worked but it changed the URLs from www.mainsite.co.uk to www.sitehost.com/uk
Ideally it would work like so...
www.sitehost.com/uk/post/20
can be accessed via
www.mainsite.co.uk/post/20
I tried mod_proxy but it didn't seem to work all the way. Anyone know how to do this? Is this even possible with Apache?

This is possible if mod_proxy is enabled in your Apache config.
Once mod_proxy and mod_rewrite are enabled place this rule in your DocumentRoot/.htaccess file of sitehost host:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?sitehost\.com$ [NC]
RewriteRule ^ http://www.mainsite.co.uk%{REQUEST_URI} [L,P]
P flag is used for proxying the request to external URL.

Related

Apache redirect keeping URL

I'm making a JavaScript web app running on an Apache 2 server. I'm wondering if it's possible (either with mod_rewrite or some other mod) to make any path you type load the index.html from the root path, but keeping the URL?
For example: "example.com/blah/blegh" will load "example.com/index.html", but the address bar will still have "example.com/blah/blegh". Same if you tried typing "example.com/everything/is/index" would still load "example.com/index.html" and have "example.com/everything/is/index" in the address bar.
A simple answer about any mods I would need to use and which commands might be best would suffice. Though a code example would be very useful since I'm new to regex's and Apache rewriting.
Thank you for your time :)
Note: I'm doing this since I'm using History.js to parse URLs/titles into the address bar and tab titles while navigating (a one-page dynamic site). I'd like to be able to just load up the root index.html with the user's initial URL request and respond to users' actions that way much like a REST server.
Actually, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.
Then, the rewrite should look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html [NC,L,QSA]
Reference:
What exactly does the Multiviews options in .htaccess?
htaccess rewrite without redirect
Apache: RewriteRule Flags

Amazon Web Services - Redirect www. traffic to non www

I would like to 301 redirect www.socholotiukmma.com to socholotiukmma.com
I've followed this tutorial: https://aws.amazon.com/premiumsupport/knowledge-center/redirect-domain-route-53/ but it's not working.
I'm assuming it's because I'm redirecting to an https site. Is there another way to accomplish this?
You can achieve this using a .htaccess file.
Create a file called .htaccess and put this inside your document root (i.e. the main directory where you put your website files):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.socholotiukmma\.com [NC]
RewriteRule ^(.*)$ http://socholotiukmma.com/$1 [L,R=301]
This should then redirect everybody going to http://www.socholotiukmma.com to http://socholotiukmma.com
If you want to redirect everybody to https://socholotiukmma.com then just change the URL in the final line of the file.

subdirectories of website.com always redirect to www.website.com

I'm using Amazon Web Services' Elastic Beanstalk for a website. I bought a custom domain and transferred the DNS settings to AWS following this tutorial.
After waiting I followed this tutorial.
I set it so if I was to enter website.com it would redirect www.website.com. However if I was to enter website.com/login it would redirect to ww.website.com without the subdirectory.
What I would like is if someone was to type website.com/login they would get redirected to www.website.com/login.
The reason I would like to the 'www.' is for consistency and SEO. How can I do this using AWS?
what your looking to do in terms of forcing a www. redirect can be done using mods to your htaccess file.
In your .htaccess document (FTP root directory), add the below code -
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
Replace example.com with your domain name and you should be good to go.

Redirect from old site on Wordpress to Codeigniter. Domain remain same

I'm preparing for migration from WordPress to site written via Codeigniter. I use htaccess very seldom, and never redirection.
My site is working now and clients visit my site. And I cannot just upload new site.
So I tried to practise with one page for redirection to another created for testing. I tried with encoded and decoded URL but without success; however, as written in the manual, it should be a simple:
Redirect [status] URL-path URL
.htaccess:
RewriteEngine On
Redirect 301 /?wpsc-product=подвеска-сова-медь-duplicate http://domain.com/?page_id=851
Also, Apache has RedirectMatch and RewriteRule [301] and they are loading server, so I prefer to use simple redirects (I have CPU load limitation on my hosting).
I have about 500 links.
Redirect OR RedirectMatch directive from mod_alias cannot match query string. You must use mod_rewrite like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} wpsc-product=подвеска-сова-медь-duplicate [NC]
RewriteRule ^/?$ http://domain.com/?page_id=851 [L,R=301,B]
Make sure to keep this rules on top of your .htaccess.
Reference: Apache mod_rewrite Introduction

Forcing HTTPS for a specific url

How, in htaccess, can you force a URL to be HTTPS at the beginning even if it was specified at HTTP?
E.g. the follwoing urls
/subscribe/spanish
/subscribe/english
I'm assumming there is some kind of regex that can be used with /subscribe at the start?
Yes, you can use following rule:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^subscribe/ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE,NC]
This will force https if:
URI starts with /subscribe/
URI has http scheme