Htaccess rule on sitemap filename for multiple domains - .htaccess

I have 2 domains: firstdomain.com and seconddomain.com that share the same platform.
My sitemap files are named:
www.firstdomain.com/sitemap/www.firstdomain.com.xml
www.seconddomain.com/sitemap/www.seconddomain.com.xml
Google can access www.firstdomain.com/sitemap/www.seconddomain.com.xml
Is it possible to prevent this with an .htaccess rule? Can I check the domain name specified in the file name?

Can this work ?
RewriteRule %{REQUEST_FILENAME} !(%{HTTP_HOST}\.xml)$ [L,R=404]

Related

Exclude Redirect rule on an Alias domain - for specific file (Robots.txt)

I have my main site: example.com that contains all files on its root folder.
I have a new domain example.net, that I want users to use as an alias domain, so users will actually see the exact content of example.com and its files, yet see in their address bar the site example.net.
But, I don't want Google to index example.net site at all, as this would be duplicate content.
Therefore, I want to exclude it using robots.txt, but if I use an alias domain, it will try to read robots.txt of example.com.
What can be the solution? any way to exclude the file?
You can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.net$ [NC]
RewriteRule ^robots\.txt$ robots-net.txt [NC,L]
Add your robot rules in the file robots-net.txt to be read with robots.txt but only when accessed from example.net.

htaccess redirect from folder with subdirectory to single path directoy

Previously my site was in wordpress, now converted into html.
I have 500+ pdfs that needs to redirect from
mysite.com/wp-content/themes/my-theme/pdfs folder to mysite.com/pdf/
Do you have server-level access to the site? If so I would create a symbolic link in the public root directory of your website to wp-content/themes/my-theme/pdfs and call it pdf.
If all you can do is .htaccess, then you can create a file like this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^pdf/(.*)$ /wp-content/themes/my-theme/pdfs /$1 [R=301,NC,L]
You might check out a great tutorial on rewrite rules.
I tried like this it works for me.
RewriteRule ^wp-content/themes/my-theme/pdfs/(.*)$ /pdf/$1 [R=301,NC,L]

htaccess to redirect dynamic urls to new directory

I have a PhpBB3.2 forum on my domain in the directory named forum:
http://www.domain.com/forum/
I want to move the forum to http://www.domain.com/ (in the root), but I also want to keep external and internal old links to keep working. How can I redirect the following URL to its new location?
http://domain.com/forum/viewtopic.php?f=4&p=384901
to
http://domain.com/viewtopic.php?f=4&p=384901
Kind regards,
Daniel
You can use this rule as first rule in forum/.htaccess file:
RewriteEngine On
RewriteRule .* /$0 [L,NE,R=301]

.htaccess redirect to subfolder depending on domain navigated to

I am setting up two wordpress sites on one shared hosting plan for a client. 123-reg says on the decription that many sites can be hosted on the same server so I thought this would be a simple click of a button thing but clearly not.
I have two sites sitting in 2 separate sub directories; FolkstockFestival and FolkstockArtsFoundation. I also have two domains www.folkstockfestival.com and folkstockartsfoundation.com. I need each domain to go to its corresponding sub directory.
I thought you'd be able to do this with the DNS settings but I haven't found a way to do that so I think .htaccess is the way forward. With mod_rewrites, is there a way to direct the user to the right directory depending on which domain is requested? The .htaccess file would be in the root directory.
I do not want the sub-directory to show on the domain so www.folkstockfestival.com shows as is but directs to the correct site.
Many thanks
Use DNS to make both of your domains pointing on your server, and use this htaccess :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www\.folkstockartsfoundation\.com [NC]
RewriteRule ^(.*)$ /FolkstockArtsFoundation/$1 [L]
RewriteCond %{HTTP_HOST} www\.folkstockfestival\.com [NC]
RewriteRule ^(.*)$ /FolkstockFestival/$1 [L]

htaccess rewrite all pages to same page on another domain

So I've been looking but so far can;t find something that I'm looking for exactly. Looked at this article How can I forward ALL pages to the same exact page on a different domain using .htaccess? but it seems to only redirect my home page.
Currently, I'm using WordPress and I need to be able to forward all pages to a new domain. For example, domain1.com/about-us needs to go to domain2.com/about-us. But I have about 50 pages this needs to work on. I would like to see if there is a 1-5 line code to use for this to work.
Thanks!
Try putting this (above any wordpress rules) in the htaccess file in domain1.com's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} domain1.com [NC]
RewriteRule ^(.*)$ http://domain2.com/$1 [L,R=301]
If your 2 domains are one different webservers, or don't share a common document root, you can just use mod_alias, adding this to the htaccess file in domain1.com's document root:
Redirect 301 / http://domain2.com/

Resources