I have a domain
http://www.example.biz/
I developed a site and put the code in a sub folder on this domain for example, the site is at
http://www.example.biz/site
now, I wanted to point my main domain to this folder so that when user visits example.biz he actually sees example.biz/site and for that, I added the below lines in .htaccess
RedirectMatch ^/$ /site/
it works perfectly however, the url user sees is
http://www.example.biz/site
I do not want that, I wanted user to only see http://www.example.biz as URL but this domain should point to the sub folder invisibly. How should I do that ?
Using mod_rewrite you can use the below rule, now when you access http://www.example.biz it will show the index file from for site/.
RewriteEngine On
RewriteRule ^$ /site/ [L]
Or if you want to show every file try with below,
RewriteEngine On
RewriteRule ^(/|.+)$ site/$1 [L]
I found a simpler solution,
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.biz$
RewriteRule !^site/ /site%{REQUEST_URI} [L]
Related
I have a full site setup at mysite.com/2/
I want urls like:
mysite.com/about to redirect to mysite.com/2/about
mysite.com/work/photos to redirect to mysite.com/2/work/photos
I was hoping I could solve this and add the /2 after the domain through the htaccess file and not have to move the whole site up a level.
Try the folowing code if you want redirect
RewriteEngine On
RewriteCond %{REQUEST_URI} !(about|work/photos)/(2)
RewriteRule ^(about|work/photos)/(.*)$ /$1/2/$2 [R=301,L]
If you need only internal redirection change the last line with this :
RewriteRule ^(about|work/photos)/(.*)$ /$1/2/$2 [L]
If you want to change all requests :
RewriteEngine On
RewriteCond %{REQUEST_URI} !/(2)
RewriteRule ^(.*)/(.*)$ /$1/2/$2 [R=301,L]
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]
The following code works perfectly to redirect an external URL to a subdirectory on my site:
RewriteCond %{http_referer} abc\.com [NC]
RewriteRule ^$ my-subdirectory/ [R=302,L]
This code tells anyone navigating from abc.com to my website to be redirected to the subdirectory listed (e.g. mywebsite.com/my-subdirectory).
But what I really want is to redirect a referring subdirectory. in other words: abc.com/some-subdirectory. How do I add "some-subdirectory" to the first line of the above code to have abc.com/some-subdirectory reroute to mywebsite.com/my-subdirectory?
Try:
RewriteCond %{http_referer} abc\.com/some-subdirectory [NC]
I think you need something like this :
RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L]
And look at here
So, this is my .htaccess code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.mydomain.com/folder/$1 [R=301,L]
The idea was to have www forced upon each user, no matter if the user visits my domain with or without www and at the same time, that user needs to be redirected to "folder" or in other words to www.mydomain.com/folder .
Although this code works perfectly, I want it also to redirect users to www.mydomain.com/folder when they go anywhere on mydomain.com domain except /folder. For example: (www.)mydomain.com/index.html (or any other page) and (www.)mydomain.com/anyotherfolder needs to be redirected to www.mydomain.com/folder
Thank you.
Add this additional rule after your existing rule:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^folder http://www.mydomain.com/folder/ [R=301,L,NC]
What I am trying to do is be able to point something like username.domain.com to index.php?url=username. I have been browsing around Google/StackOveflow and have not been able to find anything that will benefit me.
Best Regards.
Add these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com$ [NC]
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^ /index.php?url=%1 [L]
The first condition makes sure the requested host isn't www.domain.com or domain.com, the next line matches and groups the subdomain name, and the rule itself rewrites everything to /index.php with a query string url and the subdomain (backreferenced using %1).