Multiple Domains to Display Content from Landing Pages on Another Domain - apache

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');

Related

Rewriting dynamic url's using apache rewrite

I have a anchor tag in my html content like this class="list-content" href="/abcd/test.html".
and this is in a lot of places in my html for a list of some results.
I need to append all these URLs that are in "href" by appending a prefix.
For example: /abcd/test.html should be dynamically changed as newprefix/abcd/test.html
If i have another one like /xyz/some.html then this should be changed as newprefix/xyz/some.html
I have explored different solutions over the internet and I have not found something that would fit my problem.
To implement an external redirect to prepend /newprefix to these requests you could do something like the following near the top of the root .htaccess (or server config).
For example:
RewriteEngine On
RewriteRule ^[^/]+/[^./]+\.html$ /newprefix/$0 [R=302,L]
The above will redirect requests for /abcd/test.html or /xyz/some.html to /newprefix/abcd/test.html and /newprefix/xyz/some.html respectively. Anything that matches the pattern /<something>/<file>.html.
$0 is a backreference that contains the URL-path that is matched by the RewriteRule pattern.
Note that this is not "url-rewriting" since you stated in comments that you do not want to "hide" the /newprefix part of the URL from your users. An external redirect is therefore the only solution if you are intending to use Apache / mod_rewrite (as tagged).
Aside: This is not particularly good for SEO, your users or your server since the user is externally redirected everytime they click one of your links, potentially doubling the number of requests that hit your server and slowing your users.

hide target url when redirecting using htaccess

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?

Dynamic URLs + SEO

I have a website that generates dynamic urls for all content.
It uses a function to show the content on index.php page and it's called by "action".
So, if the user wants to signup, there is a signup function calling it.
If the user want's to browse downloads page, there is a downloads function calling it.
Something like this:
index.php?action=signup
index.php?action=downloads
index.php?action=news&type=type&id=id
In the last case are the news.
The news are divided by type and ID, both numerics.
Type can be: article, update, etc.
My question is: HOW and WHAT must I do in order to transform it all on friendly URLs?
Presuming you are on an apache server, you will want to use a .htaccess file, and a method of using rules to rewrite URLs, not surprisingly called RewriteRule.
There's a ton of information through google if you search for .htaccess RewriteRule, but a great starting point is http://corz.org/serv/tricks/htaccess2.php.
You will essentially end up by putting a file called .htaccess in your public web files folder, with something like this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(?:/(.*)){1,3} index.php?action=$1&type=$2&id=$3 [R,NC]
Note: I've not tested the above, and it will differ depending on how you want your pretty link to look.

Proper 301 redirect for sites

I have a bit of a complex question. I am moving sites from
http://www.hikingsanfrancisco.com
to
http://www.comehike.com
The directory structures will not be the same throughout both sites. What are some of the best practice things I can do in order to retain most of my existing SEO strength in both the general domain and individual pages for searches related to the other pages?
Thank you,
Alex
If most of the URLs are staying the same and just the domain is changing, you could create an .htaccess file in the root folder at the old site with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.comehike.com/$1 [R=301,L]
This will make hikingsanfrancisco.com/some-page go to comehike.com/some-page.
Otherwise in that same htaccess file you could add a line for each redirect. So if hikingsanfrancisco.com/big-hikes is now going to comehike.com/even-bigger-hikes the redirect would look like:
Redirect 301 /big-hikes http://www.comehike.com/even-bigger-hikes
That 301 tells Google to now consider the new URL correct.
To redirect the whole site no matter what to the new URL you could use this:
Redirect 301 / http://www.comehike.com/
A 301 Redirect, page by page, is the best option (If you can use regular expressions is easier). Redirect the old page to a page in the new site with similar content.
Use the change of address tool in Google Webmasters tools.
Try to contact some of yours referrals to change the links that target your site.

Using Apache mod_rewrite to remove sub-directories from URL

I'm managing an instance of Wordpress where the URLs are in the following format:
http://www.example.com/example-category/blog-post-permalink/
The blog author did an inconsistent job of adding categories to posts, so while some of them had legitimate categories in their URLS, at least half are "uncategorised".
I can easily change Wordpress to render the URL without the category name (e.g., http://www.example.com/blog-post-permalink/), but I'd like to create a mod_rewrite rule to automatically redirect any requests for the previous format to the new, cleaner one.
How can I use a mod_rewrite recipe to handle this, taking into account that I want to honor requests for the real WordPress directories that are in my webroot?
Something as simple as:
RewriteRule ^/[^/]+/([^/]+)/?$ /$2 [R]
Perhaps would do it?
That simple redirects /foo/bar/ to /bar.