Use both subdomains and subdirectories in Magento multistore? - magento

I currently have a store in Magento with several store views for different languages as example.com/sv/, example.com/fi/ etc. Now I want to add a store to a subdomain as test.example.com but I can't make it work.
I added a new store and a new store view for the subdomain and then changed the Base URL for this. I have created the subdomain and it points to the location of the magento installation. I have also added different lines in the .htaccess file, tried some variations of the ones below.
SetEnvIf Host .*newstore.* MAGE_RUN_CODE=newstore
SetEnvIf Host .*newstore.* MAGE_RUN_TYPE=website
RewriteCond %{HTTP_HOST} .*newstore\.com [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:newstore]
RewriteCond %{HTTP_HOST} .*newstore\.com [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]
But nothing works. When I try to access the subdomain I get redirected to the main store. But I can access the new store as a subdirectory, it's supposed to be like this test.example.com but I have to write example.com/test.
Is what I want to do even possible?
Update 15-04-09
I found a redirect in the .htaccess file that caused the subdomain to be redirected to the main store. I removed it and now I can access the subdomain but the page is just white and it says "Index of /" etc. so I don't get the magento store view.

I use this code in my .htaccess that does what you want:
SetEnvIfNoCase Host "^it\.mystore\.com$" MAGE_RUN_TYPE=website MAGE_RUN_CODE=ws_it
SetEnvIfNoCase Host "^pt\.mystore\.com$" MAGE_RUN_TYPE=website MAGE_RUN_CODE=ws_pt
SetEnvIfNoCase Host "^fr\.mystore\.be$" MAGE_RUN_TYPE=store MAGE_RUN_CODE=fr_be
SetEnvIfNoCase Host "^nl\.mystore\.be$" MAGE_RUN_TYPE=store MAGE_RUN_CODE=nl_be
Also make sure you have properly defined the Base URL (in your example: test.example.com) in System > Configuration > General Web > Secure and Unsecure for your new website or store

Related

Using mod_rewrite to redirect all pages in folder on old domain to index of new domain

I'm trying to redirect all pages on an old site (wellnowwhat.net/nin/*.*) to the index of a new site (sykonaut.net/nin_old/). I only have access to the new site's .htaccess (the old site is owned by a friend), so I'm testing going the opposite direction. I can redirect the root (sykonaut.net) to his root (wellnowwhat.net) using mod_rewrite, but I cannot redirect my nin_old directory to his nin directory. I'm guessing I wouldn't be able to redirect the opposite direction, either. Here is [the entirety of] the code in my .htaccess:
AddHandler php5_2-wrap .php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.sykonaut.net$ [NC]
RewriteRule ^/nin_old(.*)$ http://www.wellnowwhat.net/nin [R,NC,L]
It does not work. Anyone know why?
Place your .htaccess in the nin_old directory.
RewriteEngine on
RewriteBase /nin_old
RewriteRule ^.* http://www.wellnowwhat.net/nin/ [R,NC,L]
When you redirect to an external URL to a directory, I would add the trailing slash as this reduce an extra redirection.
Also when you test everything and it's all right, change R to R=301 as this is preferred by most search engine for Permanent Redirection.
In apache 2.0 and higher, the prefix (leading "/") is removed from the URI before it's put through the rewrite engine for rules in the .htaccess file. Try removing the leading slash from your regular expression in your rule:
RewriteRule ^nin_old(.*)$ http://www.wellnowwhat.net/nin [R,NC,L]

mod_rewrite to shorten url files path

I am having a bit of difficulty getting mod_rewrite to do what I need it to do.
We have a group of virtual subdomains in a Drupal install. So, academics.univ.edu, about.univ.edu, etc are all part of the same core Drupal install.
File access currently is academics.univ.edu/sites/all/academics/files/myfile.jpg. However this path will also work as about.univ.edu/sitse/all/about/files/myfile.jpg or any other valid subdomain.
We'd like to use mod_rewrite to accept academics.univ.edu/files/myfile.jpg and deliver the file from the above location.
Here's what I've tried:
RewriteCond %{REQUEST_URI} ^(about|academics|bursar|calendar)\.univ\.edu\/files\/(.*)$ [NC]
RewriteRule ^/sites/all/files/$1/$2 [L,NC]
I'm probably going about this the wrong way, but I wanted to check on it. I can get the subdomains to work by making separate rules using HTTP_HOST, but I wanted less rules in the file. Also, I can't get HTTP_HOST to work on sites that exist as a subdirectory in a subdomian. For instance, undergrad.univ.edu/biology/files/myfile.jpg should deliver /sites/all/biology/files/myfile.jpg
You can't match a host in the %{REQUEST_URI}, you need to use %{HTTP_HOST}, then use the %1 backrefernce to access that match. The actual URI can be matched in the rule itself. Something like this:
RewriteCond %{HTTP_HOST} ^(about|academics|bursar|calendar)\.univ\.edu$ [NC]
RewriteRule ^files/(.*)$ /sites/all/files/%1/%2 [L,NC]
The %1 references the match (about|academics|bursar|calendar) in the RewriteCond and the $1 references the match (.*) in the RewriteRule. So that example will take a request to http://about.univ.edu/files/foo.html and rewrite the request to /sites/all/files/about/foo.html.
Also, if this is in a virtualhost or server config, you need a "/" in between "^" and "files" in the RewriteRule.

mod_rewrite: directing a domain into a subfolder (without vhost)

I have two domains that are aliases, domain1.com and domain2.com
Currently they are both directed into the same place, the root of my web space. However, I wish to separate them into independent pages and direct domain2.com into a subfolder with different content.
I understand that the correct way to do this is using Apache Virtual Hosts. However, my service provider does not allow me access to that functionality so I'll have to solve it using mod_rewrite.
What I need is something that directs www.domain2.com and domain2.com to subfolder/ (which should trigger index.php). Also, www.domain2.com/file.txt should go to subfolder/file.txt, etc... This is what I came up with:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} domain2\.com [NC]
RewriteRule ^(.*)$ subfolder/$1 [L]
</IfModule>
However, when I run it and go to domain2.com, I get 500 Internal Server Error and the log file says:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
To test what's going on I made a small php script that prints out the string that it gets.
I also modified the rule:
RewriteRule ^(.*)$ subfolder/test.php?string=$1 [L]
Now when I go to domain2.com or domain2.com/asd, it prints out: subfolder/test.php
Somehow it gets into recursion and prints itself. Whereas, if I use the following rule:
RewriteRule ^abc(.*)$ subfolder/test.php?string=$1 [L]
Then domain2.com/abcdef prints: def
I can't figure out what I'm doing wrong. Do you have any suggestions?
Thanks!
It could be that the rewrite rule applies to subfolders of the one whose .htaccess it appears in. Does it help to add a condition that blocks the rewrite for URLs that already start with subfolder/?

Using .htaccess to serve static files via a subdomain

Right, excuse my stupidity, I've looked through a load of examples on t'interweb but I don't think I've found what I'm looking for.
I have a website, photography.example.com is the main site but I also want to have another subdomain to serve static files, for example static.photography.example.com.
If I request a file (e.g. http://static.photography.example.com/js/jquery.js) I want that file to be retrieved from the non-static domain, allowing me to keep my file structure completely untouched but using multiple domains to allow more concurrent http requests.
I don't want to throw any http responses that would make the browser thing the file has been moved, I just want to mirror the files from the normal domain to the static domain. After this I would proceed to set far future expired to improve caching etc.
How do I achieve this using .htaccess?
EDIT 1
So after a bit of messing around I have come up with this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ http://photography.example.com/$1 [L]
But this actually redirects to the domain I'm trying to read, I want it to serve the file up under the static domain name, any help with modifying this script would be greatly appreciated.
EDIT 2
So I've amended my DNS and waited a few days for it to propagate but the CNAME technique doesn't work either. Here's the entry:
In your question, you're talking about:
Adding Expire headers for caching
Splitting resources across domains
For Item #1, you can edit your httpd.conf/.htaccess file on your main domain (it doesn't hurt doing it on your whole website, no?)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/x-javascript A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
</IfModule>
Item #2 doesn't need any Apache configuration - just configure your static.photography.example.com DNS entry with CNAME photography.example.com. That should do the trick.
Or you can edit your httpd.conf and add a ServerAlias
<VirtualHost xx.xxx.xxx.xx:80>
DocumentRoot /
ServerName photography.example.com
ServerAlias static.photography.example.com
</VirtualHost>
So for now, you don't need a separate virtual host with dedicated Apache configuration.
Here are a few other reasons why you'd want a separate domain, and a separate virtual host with dedicated configuration:
Your main domain has cookies and you want to use a cookie-free domain
You actually want to use a CDN (or your Amazon S3 account to reduce bandwith on your primary hosting)
If you want one of those, or if your caching needs are too complex (you don't want to cache all JS/CSS/images, but rather a subset of it), then your only solution is: get your hands on your httpd.conf and write separate configurations for each domain
My understanding to the question is to REDIRECT
http://static.photography.example.com/js/jquery.js
to get the file from following address (without changing the URL on the browser):
http://photography.example.com/js/jquery.js
But keep URL to all existing files like the following to NOT REDIRECTED:
http://static.photography.example.com/images.jpg
If it is true then this .htaccess should work:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)?.photography.example.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://photography.example.com/$1 [P]
Moreover you can also use MAPPING if you have a complex rules like:
RewriteRule ^/file1\.js$ http://photography.example.com/file.js?q=444 [P]
RewriteRule ^/file2\.js$ http://photography.example.com/file.js?q=345 [P]
RewriteRule ^/file3\.js$ http://photography.example.com/file.js?q=999 [P]
create a text document (e.g. map.txt) in the folder with .htaccess and put in the following:
file1 444
file2 345
file3 999
The .htaccess will have the following look:
# Set a variable ("map") to access map.txt from config
RewriteMap map txt:map.txt
# Use tolower function to convert string to lowercase
RewriteMap lower int:tolower
# Get requested file name
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.js$ [NC]
# Seek file name in map-file
RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND
# Perform rewriting if the record was found in map-file
RewriteRule .? http://photography.example.com/file.js?q=${map:${lower:%1}} [P]
I think you would need the CNAME record to pass the request for static.photography.example.com to your server and the have .htaccess parse requests for static.photography.example.com in a special manner.
Adding the following rewrite rule to .htaccess should do the trick
RewriteCond %{HTTP_HOST} !^(www\.)?photography.example.com$ [NC]

Ko3 - URL Rewriting problem - Removing index.php

I'm developing a website using Kohana 3 (1rst time I use a framework). Locally, everything works perfectly. At the moment, I have a default template controller, a multi-language support and my 'index.php' is correctly removed. So before going further, I tested if it worked on my server and I got an endless loop.
I followed the tutorial from the unofficial wiki for the multi-language implementation: http://www.kerkness.ca/wiki/doku.php?id=example_of_a_multi-language_website
A redirection to the default language occurs if the language is not specified in the uri so I figured the problem might have come from there even though it worked locally, so I removed it to see what happens without the redirection. Now, I can see my home page, but whatever the uri is in the web browser, the home page will always be called. I inserted the following line in my home view to check what the uri was:
request::instance()->uri() and effectively, the uri is always: /en/home/
I put the index.php back (in the bootstrap) and everything worked fine again, even with the redirection to the default language.
My first guess was that the uri isn't rewritten correctly, so I tried to change the .htaccess but no success...
Here's my .htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /dev/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
(btw I also tried the other RewriteRule in the unofficial wiki, doesn't work either)
Additional info:
Host: WebHostingPad
Apache: v2.2.11
PHP: 5.2.9
Rewrite_Module is activated
Thank you, I would really appreciate your help because I've been trying to fix this for days now and it's really starting to annoy me ;)
The only thing you have to change in order to get rid of index.php in URL is to set the 'index_file' param in Kohana::init ( bootstrap.php ) to FALSE ( everything else can cause an error ).
So the Kohana::init looks like this;
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
If it worked with the original .htaccess, there's no need to change it at all.
The problem came from $_SERVER['PATH_INFO'] which returned no value...
This issue can be solved by adding the following line to the php.ini:
cgi.fix_pathinfo=0

Resources