I'm running a project site that has a zend framework in one folder, and a Project Pier (sort of Basecamp) install in a completely different folder (because it was installed way earlier, initially running from another domain).
The domain I registered for this project redirects to the zend/public/ directory with the following rule in my root folder:
RewriteCond %{HTTP_HOST} ^www.visiondating.nl$
RewriteRule ^(.*)$ files/zend/public/$1 [L]
This works fine, but then I figured I wanted the Project Pier page to be accessible from the same domain even though it's running from a completely different location on the server. So I wrote this:
RewriteCond %{HTTP_HOST} ^www.visiondating.nl$
RewriteCond %{REQUEST_URI} ^/project
RewriteRule ^(.*)$ cria/$1 [L]
RewriteCond %{HTTP_HOST} ^www.visiondating.nl$
RewriteCond %{REQUEST_URI} !^/project
RewriteRule ^(.*)$ files/zend/public/$1 [L]
What I'm trying to do here is redirect visiondating.nl/project/index.php to root/cria/project/index.php (where Pier is running), and redirect all other traffic on that domain to Zend.
What am I doing wrong?
You could just run Project Pier on pier.visiondating.nl. It's easy enough to make RewriteConds filtering that.
Related
After redirecting my client domain to my server i created rewrite rule in root folder .htaccess file to point domain to a subfolder1 (joomla website):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subfolder/
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Everything worked fine but today i found out that i can access any other subfolder in my server by entering for example: myclientdomain.com/subfolder2 and what's worse google can index that and show it in search results.
If there is any way to redirect a domain in a way that I won't be able to access any other folder on my server?
I would really appreciate help as I searched throughout google for answer, my server tech support said that they don't really support these kind of problems (they only gave me a piece of code from above) and I don't really know anything about .htaccess rules and how it works.
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder\/?(.*)?$
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Change above rule to:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
# if current URI is not starting with /subfolder/ then route to /subfolder/
RewriteRule ^((?!subfolder1/).*)$ subfolder1/$1 [L,NC]
Through a little research I came up with an htaccess rewrite rule in my development directory that takes a wildcard subdomain to its matching instance name in my development folder. I will admit I know little to nothing about this so help is really needed. So the current htaccess behaves as such:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.mydomain\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [QSA]
example
instance_folder_name.mydomain.com
redirects to
public_html/development/instance_folder_name
this works great because it allows me to have development websites in the development directory and i dont have to be constantly creating subdomains for each site.
the problem I am having is how to approach the following scenerio:
I use virtual domains as an add on component in Joomla so that several domains are being managed by one single Joomla install. So i may have the following subdomains...
client1.mydomain.com
client2.mydomain.com
client3.mydomain.com
that all need to go to
/public_html/development/client1
I guess what i need is a general rule on how to handle all wildcard subdomains, but with exceptions for client1, client2, client3 for example
You can have a separate rules for these 3 subdomains and add an exclusion condition in the older rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(client1|client2|client3)\. [NC]
RewriteRule ^((?!client1/).*)$ /client1/$1 [L,NC]
RewriteCond %{HTTP_HOST} !^(client1|client2|client3)\. [NC]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.mydomain\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [L]
I have two folders on FTP root. site_v1 and site_v2. site_v2 has new version of website and site_v1 has older version. I wanted to point my domain to site_v2, the latest version. So I made an .htaccess on root as under.
RewriteCond %{HTTP_HOST} example.com
RewriteCond %{REQUEST_URI} !site_v2/
RewriteRule ^(.*)$ site_v2/$1 [L]
This works well. When I open http://example.com; site_v2 loads seamlessly.
Then, for site_v1, I created a sub domain http://old.example.com and pointed it to site_v1 folder; I get this error when I run http://old.example.com.
The requested URL /site_v1/site_v2/site_v1/index.html
was not found on this server.
I am clueless. It seems that http://old.example.com is still pointing to site_v2 because of .htaccess on root. What could be the solution so I can force old.example.com to load in site_v1?
Try changing your rules to:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/site_v[0-9]/
RewriteRule ^(.*)$ /site_v2/$1 [L]
RewriteCond %{HTTP_HOST} ^old\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/site_v[0-9]/
RewriteRule ^(.*)$ /site_v1/$1 [L]
This way, the host matching against the `%{HTTP_HOST} var won't overlap.
I am dealing with following problem:
I have one main domain "example.com" and multiple subdomains:
one.example.com
two.example.com
three.example.com
etc. on server.
I have content for this subdomains in folders:
./one/ -> one.example.com
./two/ -> two.example.com
./three/ -> three.example.com
etc.
So to serve content from these folders to subdomains, I use following htaccess file:
RewriteCond %{HTTP_HOST} ^one.example.com [NC]
RewriteCond %{REQUEST_URI} !^/one/.*
RewriteRule ^(.*) /one/$1 [L]
It works fine, but my content for subdomains is also accessable from URL:
one.example.com/one/my-content
such as
one.example.com/my-content
etc. So it is duplicite.
This is one problem I need to solve.
Second is, that content for example.com is accessable from
whatever.example.com
(a.example.com, b.example.com etc.)
so again duplicite.
So my question is: how to redirect/disable URLs that are creating duplicite?
Thanks a lot, I've tried a lot of versions of code, but with no effect.
I solved this issue by redirecting all requests to a subdomain to that folder and all requests to the base domain to another, like this:
RewriteCond %{HTTP_HOST} ^one\. [NC]
RewriteRule (.*) /one$1 [L]
RewriteCond %{HTTP_HOST} ^two\. [NC]
RewriteRule (.*) /two$1 [L]
RewriteRule (.*) /zero$1
It seems to work, but I'm having my URL modified on the browser too. How do I avoid this from happening?
For your first issue, you can add a rule, that redirects any requests to that folder and withing that directory to a page that does not exists (so that it throuws a 404 error)
RewriteCond %{HTTP_HOST} ^one\.example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} ^one/
RewriteRule . /notexists.html [L]
For your second issue, this should not happen since when you ask for a.example.com/folder/file.html it gets redirected internaly to a.example.com/a/folder/file.html (there is no way to get the content in the parent directory of 'a' )
I run TYPO3 with a normal site and a subdomain in the same TYPO3 installation. On the normal site, automatically a mobile device is detected and then rerouted to the subdomain.
In my subdomain the visitor is redirected to the correct page in the TYPO3 tree, using following .htaccess file.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^m.mysite.com [NC]
RewriteRule ^(.*)$ http://m.mysite.com/index.php?id=74 [L]
What happens is that the visitor ends up in an endless loop where he is sent to the TYPO3 site and then to the subdomain and back again.
To get this working, I also need to change the working directory to www.mysite.com (I also have another provider where I can make these changes using a cpanel, and that site runs perfectly). I have been looking everywhere and have tried almost anything, but I simply do not have enough knowledge to change the working directory.
So what code should I use to change the working directory?
Use RewriteCond to not follow this rule for index.php.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^m.mysite.com [NC]
# Failing the index.php check, the usual test is to look for any
# existing file
# EDIT: Changed URI to start with / - should work per comments
RewriteCond %{REQUEST_URI} !^/index.php
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://m.mysite.com/index.php?id=74 [L]