I am planning to create some addon domains through cPanel, I'm aware that their content can be accessed by visiting addondomain.maindomain.com and maindomain.com/addondomain - this could lead to duplicate content with search engines, amongst other things, so I would like to prevent this if possible.
After some research it seems the best (probably only) option would be to use .htaccess and rewrites so that the addon domain can only be accessed at www.addondomain.com - what is the best way to go about doing this and can I have the .htaccess file within the maindomain.com directory or will I need it for each addon domain I create?
Any help would be much appreciated, thank you :)
RewriteRule ^addonedomain/(.*)$ http://addondomain.maindomain.com/$1
this code will redirect user from maindomain.com/addonedomain directory to addonedomain.maindomain.com !
it's better to put this code in .htaccess file in root of add-on domain!
Related
I little while ago I came across a tutorial which took me through setting up a php site and then moved everying into a folder called 'public' after which it created a .htaccess file with a ReWrite in it to change every request to 'domain.com' to 'domain.com/public', I am unable to recreate this successfully or find the site. Is there a security benefit to such an approach? or am I better off using htaccess for other options such as -Indexes and -FollowSymLinks?
I host in siteground, on a multiple domain account,
Main domain is pointed to public_html, so it's a bit dangerous for the rest of sites in the account to use it (unwanted deletes, hacks, and so...)
I successfully followed this guide (http://www.ianholden.com/how-to/hide-joomla-subdirectory/) to point mydomain.com to midomain.com/mydomain folder (joomla install)
But now I have a problem with existing subdomains for sites still without their own domain names, that give a 500 error when visited...
What could I use to leep my current rewrite rule mydomain.com -> mydomain.com/mydomain and make exceptions for subdomains as whatever.mydomain.com?
Thanks
The problem is that the rule that you have added to your .htaccess file will affect all other sites on your hosting account, since the .htaccess file is at the same level of all those sub-directories.
If you have too many sites hosted this way, then I suggest you go with a VPS, and then create an account for each and every domain that you have. This will ensure that your websites run smoothly and in silos.
Whatever you do to make Joomla work properly under a subdomain, will create problems for you on the long run.
I have a main domain, www.example.com, that has ranking and 'trust' in Google. I'm creating a blog, but, for various reasons, I HAVE to host it on a subdomain, sub.example.com.
I know that when a subdomain is created, Google treats it as a new site and will eventually see it as part of the main domain (after a very long while). What I'm looking for here is a way around this or a way to expedite this process. Is it possible?
Possible solutions:
Using modrewrite to rewrite sub.example.com to www.example.com/sub. I'm not too familiar with rewriting so I'm not sure if it works like this. If it does, would this be a solution to this issue?
Creating a subfolder on www.example.com like www.example.com/sub, and, in that subfolder, include a redirect to sub.example.com. That way when Google crawls www.example.com/sub it will find the link to sub.example.com. Will it then see the subdomain as part of the real domain?
Are these viable solutions? Is there anything else that could be done?
Thanks.
mod_rewrite won't let you convert the subdomain to a folder, but mod_proxy will.
You'll want something like this in your apache config file in the virtual host section for www.example.com:
ProxyRequests Off
ProxyPass /sub http://sub.example.com/
ProxyPassReverse /sub http://sub.example.com/
Then your blog is running in both places. You'd probably want to put canonical tags on it so that Googlebot knows which is the preferred one.
Google treats subdomains and subdirectories the same. They do not see subdomains as new websites.
I have a main website www.site.co.uk and one of my add on domains is addon.co.uk. Site has an htaccess as does addon. The folder of which from the root would be www.site.co.uk/addon.co.uk/.htaccess ..I think!
Anyway currently I can do redirects within addon htaccess file fine, but its a database driven site and im trying to create pretty urls for it, so:
http://www.addon.co.uk/addonsites/some.php?id=page
would become:
http://www.addon.co.uk/id/page/
The mod I have in the addon htaccess file is the following:
RewriteEngine On
RewriteRule ^id/([^/]*)/$ /addonsites/some.php?id=$1 [L]
But this has no effect.
Well, the mod_rewrite module will perform translations on requests to the server, so when anyone requests the resource located at http://www.addon.co.uk/id/page/ the server will know that http://www.addon.co.uk/addonsites/some.php?id=page is the place to go.
However, mod_rewrite does in no way modify your existing links. I.e., you should rewrite the HTML (or scripts generating the HTML) to match the "new" way of linking. E.g., if you have ... somewhere on your site, you must make sure it is changed to ....
tl;dr
mod_rewrite handles incoming requests; it does not modify your output (HTML).
I am trying to achieve something that I am not sure if htaccess can even do.
What I have is a folder structure:
myapp
some_folder
some.js
www
css
js
now the web root is pointing at www folder so i can do http://mydomain.com/js/jquery.js and it would work but what I want to do is http://mydomain.com/myapp/some_folder/some.js and it should load some.js and serve it.
Is it possible to do this in htaccess?
AFAIK, you can't point to directories outside the current web root from within .htaccess.
There is the Alias directive but in the .htaccess file, it works only below the web root. It would have to be in the central configuration file to accept absolute paths.
As far as I know, this limitation applies to all other directives that could help here, too (RewriteRule etc.)
The only workaround that comes to mind is using symlinks. Whether you can do that, heavily depends on your operating system and access to the server.
you can redirect upwards, just using the .. parent directory identifier.
for example:
RewriteRule (.*) ../$1
but only if the destination still lies within your webroot.
in your cas it seems not to, so your only chance is to create a symlink/hardlink to that directory or do some file including
alias rewriting in your server cfg file however would work.