hide target url when redirecting using htaccess - apache

I have a problem:
I have several customers with websites and e-mail-adresses. They use my providers webmail-service which is simply Roundcube.
So instead of having them all to go to
http://server20.shittyserviceprovider.com/webmail
I want them to hit their own website URL followed by /mail like
http://www.mybeautifulwebsite.com/mail
Now I tried the following:
RewriteEngine On
RewriteRule ^mail/?$ http://server20.shittyserviceprovider.com/webmail [P]
which kind of works but it does not load the functions and css of the mailprovider.
Is there a way I can get this done?

Related

Apache rewrite url and hide old url

I want to simplfy an URL but cant find how to do that.
Here is the original URL that exists and works.
https://example.com/s/732kglm
I want to use this different URL for the same content.
https://example.com/info
I can do that in apache with a redirect
Redirect permanent /info /s/732kglm
Now if I open https://example.com/info I will be redirected to https://example.com/s/732kglm but the browser shows the original URL.
I want to hide tho original URL so that user only sees the simplified URL https://example.com/info
How can I achieve this?
It sounds like you need an internal redirect. I don't have access to apache to test, but something like the following should work.
RewriteEngine on
RewriteRule "^/info$" "/s/732kglm"

Apache mod_rewrite .htaccess and conditions to avoid rewriting while url mysite.com

I'd like to make custom URL for my users so they can have their personnal art gallery displayed just like on facebook when it displays user's profile . For instance mysite.com/username will display username's gallery.
So basicaly what I've done now is something like that :
RewriteRule ^([a-zA-Z0-9]*)/?$ index.php?fc=module&module=testmodule&controller=displaygallery&url=$1 [L]
I have the gallery correctly displayed on my website, but I can't display the index page anymore using absolute mysite.com. I know we can use conditions to avoid such a situation but which one ?
So while writing the post I've just think about the line I've done and I found the solution ^^ !
Instead of using :
RewriteRule ^([a-zA-Z0-9]*)/?$ index.php?fc=module&module=testmodule&controller=displaygallery&url=$1 [L]
I'm now using :
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?fc=module&module=testmodule&controller=displaygallery&url=$1 [L]
Instead of using * I used +, which is telling Apache that it needs at least one character or more to rewrite URL so everything works fine now :)

Multiple Domains to Display Content from Landing Pages on Another Domain

We have created a bunch of landing pages on a Joomla CMS system, such that the URL for each landing page is www.domain.com/page1.html and www.domain.com/page2.html, and so on. Of course the page1.html isn't really an HTML file it is a dynamic CMS page, just rewritten with htaccess.
The goal is to have one of our other domains, something like www.uniquedomain1.com show the content of www.domain.com/page1.html. Or, another domain like www.uniquedomain2.html show the content of www.domain.com/page2.html.
This needs to be search engine friendly so we can't use URL masking. Also we can't use HTACCESS redirects as this actually changes the URL in the browser bar. Need to keep the www.uniquedomain1.com URL in the browser bar.
Tried Apache VirtualHost options without any luck. You can park in a directory but not from a URL.
Ended up parking the domains on one folder, and then creating a PHP script to detect the domain host and then use CURL to query the correct url and deliver content. This whole thing seems ridiculously over complicated, and of course CURL isn't the best option, but it is all we could get to work.
Any thoughts on how to do this, or a better solution?
You can use HTACCESS redirect rules to do it without performing a redirect.
Change the html file names to be the domain name of the desired domain like domain.tld and do something like this in an .htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?([a-z0-9\.-]+\.[a-z]+) [NC]
RewriteRule ^$ /%1.html [L]
A quick test of this worked for two of my test (sub)domains test.domain.tld and test2.domain.tld. Both properly redirected to files with the names test.domain.tld.html and test2.domain.tld.html without modifying the URL.
You could also just use your PHP wrapper script to grab the content of each of the miscellaneous html files and output them.
If you renamed all of your HTML files (as in my previous suggested answer) to be domain.tld.html you could do it fairly easily. Something might look like:
<?php
require($_SERVER['SERVER_NAME'] .'.html');

Prevent users from accessing files using non apache-rewritten urls

May be a noob question but I'm just starting playing around with apache and have not found a precise answer yet.
I am setting up a web app using url-rewriting massively, to show nice urls like [mywebsite.com/product/x] instead of [mywebsite.com/app/controllers/product.php?id=x].
However, I can still access the required page by typing the url [mywebsite.com/app/controllers/product.php?id=x]. I'd like to make it not possible, ie. redirect people to an error page if they do so, and allow them to access this page with the "rewritten" syntax only.
What would be the easiest way to do that? And do you think it is a necessary measure to secure an app?
In your PHP file, examine the $_SERVER['REQUEST_URI'] and ensure it is being accessed the way you want it to be.
There is no reason why this should be a security issue.
RewriteCond %{REDIRECT_URL} ! ^/app/controllers/product.php$
RewriteRule ^app/controllers/product.php$ /product/x [R,L]
RewriteRule ^product/(.*)$ /app/controllers/product.php?id=$1 [L]
The first rule will redirect any request to /app/controllers/product.php with no REDIRECT_URL variable set to the clean url. The Rewrite (last rule) will set this variable when calling the real page and won't be redirected.

Can Apache configuration check cookies?

My situation:
We have a mobile version of our website, and want to start redirecting mobile users to it. The plan is to do this in Apache httpd.conf or .htaccess, using something like this:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (iPhone|Blackberry|...)
RewriteRule (.*) mobile/$1
However we want there to be a way for users to override our default action of redirecting them. One way we thought to do it was to show a link on the mobile site directing back to the regular site, and store a cookie when they use that link.
Could the Apache configuration file check a cookie before redirecting?
Is there a better way?
The HTTP_COOKIE server variable contains the cookies passed from the client to the server. You can look in there to find out what cookies have been generated by a script or module.