mod-rewrite rule for sitemap.xml - .htaccess

I am using a CMS that hosts multiple websites simultaneously and I am seeking a method to properly serve sitemap.xml files for each site. I have concluded that a mod-rewrite rule will be the most effective solution for this.
My idea is to have a /sitemaps/ directory with the site map for each domain named as the domain name, i.e. /sitemaps/acmewidgets.com.xml
Since the appropriate sitemap url would be acmewidgets.com/sitemap.xml I need assistance with creating a mod-rewrite rule that will map this accordingly.
Thank you!

RewriteRule /?sitemap.xml %{DOCUMENT_ROOT}/sitemaps/%{HTTP_HOST}.xml [L]

Related

Redirect old domain to new website via htaccess?

Have an old webisite (oldwebsite.com) and want to redirect all the domain requests to the new website (newwebsite.com) via htaccess (probably).
How would you go with it? Need like all old pages to redirect to the new website homepage as the structure and pages are entirely diffirent.
This probably is what you are looking for:
RewriteEngine on
RewriteRule ^ https://new.example.com%{REQUEST_URI} [QSA,R=301,END]
In general I would recommend to implement such general rules in the http server's central configuration of the host "old.example.com". You can instead use a distributed configuration file (".htaccess"), but that comes with a few small disadvantages.

Fake subdomain for different users while still browsing same folder structure

I'd like to create fake subdomains for different users for more vanity, and to make the user (in this case a company) feel they are in a more isolated environment.
For the sake of maintainability, it's important for me that all users still browse the same files, to avoid having to update files for every single user that exists when updating the code.
My website has one public part at root, let's say www.example.com. I'd like to be able to fake the following kind of subdomains:
user1.example.com
The true URL would be www.example.com/member/?user=user1. I'd like for the folder structure to follow the same pattern. www.example.com/member/settings/?user=user1 would appear as user1.example.com/settings/ and so on.
I assume this would best be achieved with .htaccess, no?.
What is the proper .htaccess code for this?
Thank you!
based on the information you've provided here's a bit of .htaccess not tested but might do the job.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteCond %{QUERY_STRING} ^user=(.*)$
RewriteRule ^(.*)$ http://%1.example.com/$2? [R=302,L]
Once you find it working fine, replace 302 to 301
Note: It's important to note that you'll need to add a subdomain wildcard
In the end, this was super easy to solve! It wasn't solved the way I first expected though, using .htaccess. I solved it with something called wildcard subdomain.
When you register a new subdomain, enter * in the domain prefix, such as *.example.com. A folder for the wildcard subdomain will be created on your server, such as _wildcard_.example.com. Whenever you access site1.example.com, fakesub.example.com etc, the browser of the visitor will read the files in the wildcard.example.com folder.
The beauty of it all is that if I create a certain subdomain that I want to use, for example forum.example.com, this real subdomain will have priority over the wildcard subdomain, and files will be fetched from the folder for this subdomain, as opposed to from the wildcard subdomain folder.
I use PHP and need to know the subdomain to fetch the appropriate database for the current user. To do this, I use the following code:
$subdomain = explode('.', $_SERVER['HTTP_HOST'])[0]
With a wildcard SSL cert I have all of these subdomains secure.

Retrieving files from another URL on the server

I have one server two domains. I need the images and css apply to both domains. Currently I solve it using htaccess:
RewriteRule ^.*\.(css)$ http://www.rs.cz/style/$0 [L,R]
How is it possible to improve? Or at least refer to a relative path on the server?
Create one subdomain just for hosting images and static content like:
images.mydomain1.com
and another subdomain like:
images.mydomain2.com
Have both of them redirect to the same directory in the server like /var/www/common_images.

pointing to a subfolder from a subdomain

My main site www.mysite.com is using drupal
I would like to create a WP blog at blog.mysite.com (I know I can create a blogging platform using drupal but don't wanna do that, WP is best for blogging it simply rocks)
I'm quite new to .htaccess and was wondering if there's a way to get
www.mysite.com/blog pointing to blog.mysite.com (since mysite.com/blog is better for SEO)
(but not redirecting there, it just has to load from there, so visitor sees mysite.com/blog in their browser)
If you have mod_proxy enabled, you can use the [P] flag to internally proxy www.mysite.com/blog requests to blog.mysite.com. In the htaccess file for www.mysite.com's document root (above any drupal related rules):
RewriteEngine On
RewriteRule ^/?blog/(.*)$ http://blog.mysite.com/$1 [L,P]
If you don't have mod_proxy, you may need to setup WP somewhere in the same document root as your drupal site (like in /blog/) and get wordpress to work in a subdirectory. I've had mixed results in getting that to work with another CMS so not sure how much help I can give you there.
gvanto:
Thanks. I don't have mod_proxy but I think it may cause issues having it under a subdomain and accessing in this fashion (e.g. what will all the internal links be pointing to?). The 2nd option of having it in a subfolder is probably best: http://drupal.org/node/877828

Display content as root from subdomain

I have a site running on a subdomain of new.site.com and I want to be able to just put something in the .htaccess file that will display the subdomain's content as if it was in the root.
Where the site is: new.site.com
The url that I want to use: site.com
Basically what I want to do is just not move the files from the subdomain to the root of my server.
Try using a domain pointer.
EDIT:
Not sure why my answer was downed. Let me elaborate a little more.
I do this myself on my websites. In my hosting company's control panel, I have the option to create domain pointers. What this does is set a domain to use the website of another domain.
Actually found this that works incase anyone was wondering:
RewriteEngine on
RewriteBase /
RewriteRule ^$ /subdomain/ [L]

Resources