How to mask a URL in a website? - .htaccess

I want to "mask" a URL. I have a subdomain that I do not want people to know about on my website. So what I am needing help with is this:
My website is: www.example.com
I have a subdomain: sub.example.com/test.php
When someone clicks on a link that points to sub.example.com/test.php, I do not want "sub.example.com/test.php" to show in the url bar. I would like for www.example.com to show instead.

When you want to link to sub.example.com/test.php, change the link to something else, like www.example.com/sub/test.php or something. Then in your .htaccess file in the document root for www.example.com add this:
RewriteEngine On
RewriteRule ^sub/(.*)$ http://sub.example.com/$1 [L,P]
This will internally proxy any request for www.example.com/sub/ to sub.example.com. So when someone requests http://www.example.com/sub/path/file.html, they really get http://sub.example.com/path/file.html except their URL address bar still has the example.com URL. You just need to make sure to change all of your links to sub.example.com to example.com/sub/

Related

Another .htaccess redirect case

I have a site where mydomain.com and mydomain.com/frontpage serves the exact same content.
Socalled SEO experts tell me it is very bad to have the same content on different addresses. Google will cast upon me a terrible fate.
So I thought fine, I'll just redirect mydomain.com to mydomain.com/frontpage, but I'm failing miserably. I just can't wrap my head around htaccess commands.
I need to have visitors who visits mydomain.com or www.mydomain.com to be redirected to www.mydomain.com/frontpage in a way to that it becomes visible in the browser address field.
BUT nothing else must be redirected.
For example, www.mydomain.com/anotherpage must still be there.
My .htaccess is already full of a lot of rewrite rules that redirects all of these user-friendly addresses to the real urls (index.php?pageid=341) etc. So I'm thinking I would first redirect mydomain.com to mydomain.com/frontpage and then let another RewriteRule later make sure that mydomain.com/frontpage actually points to index.php?pageid=341.
But mydomain.com => mydomain.com/frontpage must be a visible redirect, while all the other rewrite rules are hidden from the user.
How does the Redirect or RedirectMatch or RewriteRule look like, that redirects visitors from www.mydomain.com to www.mydomain.com/frontpage while keeping other addresses like e.g. www.mydomain.com/anotherpage ?
Thanks.
You can insert this new rule just below RewriteEngine On line:
RewriteRule ^/?$ /frontpage [L,R=301]

.htaccess - redirect user to subdomain without changing address bar

I want to redirect visitors who go to www.example.com to www.sub.example.com, however their address (url) bar should remain the same - www.example.com. Is it possible using .htaccess or some other method, please? I'm pretty new to this. Thanks!

.htaccess invisible redirect to page within subfolder

I've tried many options in .htaccess without success. What I want to do is this:
I have Wordpress residing in its own folder, like this: site.com/folder
I want all users visiting site.com to be redirected to site.com/folder/page but in such a way that the URL doesn't change in the browser. All other URLs, such as site.com/folder and site.com/folder/page1 etc shouldn't be affected.
How to do this, in as SEO-friendly way as possible?
Thanks everyone.
You can't redirect a user to a other page from serverside without to show this to the use.
But if you need, you can use the HTML tag <frame> http://www.w3schools.com/tags/tag_frame.asp
But the bad side with this is the use always will be show "site.com" and not the real page.
But I think the best way is to proxy the result, in Apache you can do this by something like this.
RewriteEngine ON
RewriteRule ^/$ folder/page/index.php [L]

Redirect to a page if URL contains string

My business has been bought-out. As such we are re-branding and changing the URL's of our sites. I have 2 URL's pointing to one web server (the old, original URL and the new URL) and what I would like to do is have script on my pages to see if my user has visited the old URL. If they have I would then like them to be redirected to a particular html page to tell them that the site has changed and that they need to update their favourites. I do not want the redirect to be automated.
Basically any time the old URL is detected I would like them redirected to the redirect page to inform them
IF URL contains 'dls.myOLDwebsite.co.uk' THEN REDIRECT to: 'dls.mywebsite.co.uk/redirect.html'
The reason I would like to do this is because if the user is going to the new, correct address (example; dls.myNEWwebsite.co.uk) then I don't want any redirects or messages.
Can anyone assist?
I believe you're looking for this.
You need to add the following to the .htaccess file of your site
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} dls.myOLDwebsite.co.uk ^
RewriteRule ^/$ http://dls.mywebsite.co.uk/redirect.html [R=301,L]

Rewrite rules to hide an url

i need to hide full path and show shortly:
www.site.com/this/is/path/to/hide/page.php --> www.site.com
Any idea to do it with .htaccess apache and rewrite rules??
EXAMPLE:
If i type www.site.com i want open index.php (in /),
but if i go to /hidden/path i want to open file.php (in hidden/path)
mantaining browser url in www.site.com.
EDIT:
i want to see in the browser bar www.site.com and i want to open page at /this/is/path/to/hide/page.php .
thanks
As I explained in : How does url rewrite works? every rewrite triggers a new call to the rewritten URL. (HTTP 3xx code).
So the client will ask for www.site.com/this/is/path/to/hide/page.php, would be redirected to www.site.com and will be served the index page as a normal user.
There is no way to tell the client to display one URL in the browser bar instead of another, client browser will always make a new request. (Or you could impersonate any site for example)
If you are not against the use of a cookie, or can use environment variable you may be able to do something like :
RewriteRule this/is/path/to/hide/page.php / [co:knowHiddenPath=true]
The environment variable as same syntax with E instead of co.
(See http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html for cookie information)
Your index page should then check this cookie/variable to serve the hidden page or not.
Another solution would be to enable access with password to your file. So even if someone know the URL he would not access the file. Security by obscurity is does not exists.
You can I believe do that with an Alias,
Alias / /this/is/path/to/hide/page.php
This directive needs to be in your <VirtualHost>
This will use mod_rewrite and you can put this into your .htaccess
# Activate Rewrite Engine
RewriteEngine On
# Home page rewrite rule
RewriteRule ^$ /this/is/path/to/hide/page.php [QSA,L]
This will ONLY work if you hit website root (e.g. http://www.example.com/)

Resources