Mask redirected URL - .htaccess

I have an URL that redirects to another. (Both sites are hosted by myself)
How can I mask the final URL to show the first one?

The easy answer: You cannot. The browser (or any script accessing the content at that given URL) shows the user where the data is coming from - and that's the redirection target, since that's where the data is coming from.
The complx answer: You can. However this required quite a bit of work. The server internally has to fetch the data for the redirection target and forward it to the client. However strictly speaking this isn't a redirect any more that you can perform using a .htacess configuration.

Related

Azure SWA: redirect to modified version of requested route?

I set up a site using Azure Static Web Apps. I have two use cases I haven't been able to solve nicely for, and I think the same functionality might address both:
When a user is not authenticated, they're redirected to <my-site>/.auth/login/<my-auth-provider>. But, that means when they're brought back after logging in, they go to /index.html, which is not ideal. Most of the traffic to this site will be to specific leaf pages. I'd like to redirect to <my-site>/.auth/login/<my-auth-provider>?fromUrl=<the-requested-url> instead, if possible.
When a user requests a "pretty" url address e.g. <my-site>/pretty-url, I noticed that Azure SWA doesn't handle that the normal way, rewriting to <my-site>/pretty-url/index.html. I'd like it to at least try to rewrite to <my-site>/pretty-url/index.html.
It looks like neither of these are possible at the moment.
Here's a Github issue about redirecting after login, and one about enforcing trailing slashes.

.htaccess redirection keeping my orginal URL

I would like to have the following setup using .htaccess.
domain.com/test/hello.php or domain.com/index.php or any other link must show only domain.com in the URL.
Kindly share your views on this.
As implied by Jon Lin, this is not directly possible as the server cannot guess what content should be loaded. The simple rule of HTTP is that each request has its own response.
Furthermore, it should be noted that, if it were possible (by some kind of magic - perhaps by the use of AJAX), it wouldn't be good for SEO, as Google/Bing/whatever wouldn't be able to index your site.
If you really wanted to mimic the behaviour, you could run the following HTML5 History API method in JavaScript:
window.history.pushState("", document.title, "/");
This will change the address bar to show only your domain name, and will more than likely have side-effects.

Can .htaccess be configured to retain the same address on different pages?

Im configuring a desktop and mobile version of my site and was looking to use js to test for browser dimensions and then load the relevant version, however the problem is if someone shares a link from the mobile version and sends it to a desktop user then they circumvented the check. Is there a way to configure .htaccess (or some other method) to have the address bar show 'mysite.com' even though i would be loading 'mysite.com/mobile.htm'? I know i can always use media queries but that has the downfall of loading unused assets, so this method would be alot better.
Use a rewrite instead of a redirect. With a redirect, the browser is instructed to go to another address. With a URL rewrite, the server just responds with the contents of a different URL.
For just this page it will be simple, but it could be complicated, based on your site.
Another way is to include a little JS in every page to make sure you are on the right one for the device and redirect to the other if not. It would help if there was some pattern to easily determine the corresponding page.

redirect https to http without postdata loss

On my website some pages are secure and some are not. I have a search form on each of my page (as a part of a template) and when I'm on https page and launch the search, the results page shows nothing. I know I must be loosing my posted data because of the redirection. Would excluding the results page from being redirected solve my problem? I want it to be http at all times. If that's the case - what exactly do I need to put inside of my .htaccess?
If you ensure the search form uses 'http:searchurl' in the action rather than just 'searchurl' then it should work

Dynamically creating URLs for other websites

I'd like to know how websites have created URLs with other domains like these on trafficestimate.com.
I'm guessing it's some .htaccess stuff to redirect domain names to a dynamic page?
Thanks
Your URL has an GET Request. So when someone calls the page http://google.com/search with the parameters hl=en, safe=off etc., the page can process those parameters. So for instance safe=off means that you want to get back any search result. The q=site:... is your search string. In this case Google will look it up in its database and give you the results. So when you call this URL there is probably no .htaccess processing done. However you can process the URL and GET request with .htacces and i.e. redirect the user to another page.
Maybe you'll describe a bit further what exactly you trying to do/want to know. This makes explaining easier.
EDIT: After reading Gumbo's comment I looked at the Google result page. So maybe your question means the trafficestimate-URLs. They look like http://trafficestimate.com/example.org. This is really a good case for .htaccess. So using .htaccess they take the URL and redirect it to http://www.trafficestimate.com/websites/?domain=example.org. Here you have again a GET request and an application builds the page.
Some URL rewriting is probably involved. Otherwise they would have to create an existing file for every possible request.
Using Apache’s mod_rewrite in a .htaccess file is one option. But since the server identifies itself with “Microsoft-IIS/7.5”, they are probably rather using ISAPI_Rewrite, a mod_rewrite derivative for Microsoft’s IIS.

Resources