I have the following problem.
I need when people access to www.mydomain.com they really access to www.mydomain.com/folder, and they keep seeing www.mydomain.com in the URL.
How can this be done with de .htaccess of my server?
Thanks
create a .htaccess file in the root of the site with the following code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com/$ [NC]
RewriteCond %{REQUEST_URI} !^../folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9/-_.\s]+)?$ ../folder/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
RewriteRule ^(/)?([a-zA-Z0-9/-_.\s]+)$ ../folder/$2 [L]
that's all you need.
RewriteEngine On
RewriteRule ^(.*)$ /folder/$1 [L]
and try to search before you ask something! there are lots of examples like that.
Related
I searched the forum and found some questions close to what I am trying to achieve but they don't work for what I am trying to do.
We got a new client and we need to redirect the pages of his old website to the new one.
All the pages in the old website have this structure:
http://www.domain.com/index.php?option=com_content&view=article&id=158&Itemid=179
I need to redirect each page to the relevant page of the new website. The structure of the urls in the new website is like this:
http://newdomain.website.com/slug/
I am assuming that the only way to do this is through htaccess but I cannot figure out how to write the command.
Thank u in advance for any help.
try this :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://newdomain.website.com/slug/$1 [L,QSA]
Put this code in your DOCUMENT_ROOT/.htaccess file on domain.com:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^option=.+ [NC]
RewriteRule ^index\.php$ http://newdomain.website.com/slug/? [L,NC,R=301]
EDIT:
RewriteCond %{QUERY_STRING} ^option=.+?&Itemid=.*?64$ [NC]
RewriteRule ^(index\.php)?$ http://newdomain.website.com/slug/? [L,NC,R=302]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{QUERY_STRING} ^option=.+?&Itemid=.*?64$ [NC]
RewriteRule ^ http://newdomain.website.com/slug/? [L,NC,R=302]
I use this redirect because my website is inside a subfolder (www.domain.com/subfolder/)
So if someone enters the website, it will load like this: http://domain.com
What do I need to add or change in .htaccess so that it redirects automatically to https://domain.com, counting that the website is at domain.com/subfolder
I have tried various redirect codes, but no success. If someone is kind to point me in the right direction or give me a hint.
Thanks for the help.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder/index.html [L]
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule !^subfolder/ subfolder%{REQUEST_URI} [L,NC]
I have an url like this one:
http://xxxx.com/cms/
....
http://xxxx.com/cms/about-us/concept/
http://xxxx.com/cms/something/
What i want is hide the cms folder of the url.
So when i type in url http://xxxx.com/ I should be redirected to http://xxxx.com/cms/ but the cms should not be visible.
Any help?
.htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/cms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ cms/index.php [L]
The best way to do this is by changing the DocumentRoot in your apache config. In the config file just tack on "/cms" to the DocumentRoot= value and restart apache.
I have a drupal website which has been split up to two separate websites, and now I need to setup some rewrite rules in order to drive traffic to the new site.
Original website looks like this:
http://www.website.com (frontpage)
http://www.website.com/web1/subpage1 (subpage)
http://www.website.com/web1/subpage2 (subpage)
http://www.website.com/subpage3 (subpage)
http://www.website.com/subpage4 (subpage)
All references to subpages that are not in the web1-category have been removed from the website, but the pages are still published and they still show up in Google.
What I need is a rewrite rule that redirects from "website.com" to the frontpage of "new-website.com" if the user tries to access a page that is not the frontpage and not in the web1-category.
I suppose a rewrite-rule checking for the string "web1" in the URI would be the answer to my problem, but unfortunately I have no idea how to write the syntax.
Any help would be appreciated.
Thanks in advance.
EDIT:
My htaccess file with #zessx proposed solution:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^my-website\.com$ [NC]
RewriteRule ^(.*)$ http://www.my-website.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !web1
RewriteRule ^(.+)$ http://www.my-new-website.com [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
This is what you need :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !web1
RewriteRule ^(.+)$ http://new-website.com [L,R=301]
A colleague of mine, found a solution:
RewriteCond %{REQUEST_URI} !^/web1(/|$)
RewriteCond %{REQUEST_URI} !^/admin(/|$)
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^([\w/]*)$ http://www.new-website.com [L]`
I have a website hosted in cpanel. Files of this website are in a folder. In the panel there is no possibility to host a domain to this folder, so when I go to www.mydomain.com I can see all folders. I would like to redirect my registered domain to a folder where my website is.
I use htaccess file and try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^(.*)$ www.hostdomain.com/folder/$1 [L]
but it doesn't work.
This:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^(.*)$ folder/$1 [L]
and still nothing.
What I do wrong? I would be grateful for some advice.
Edit: I dealt with it.
I use:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/folder/
RewriteRule ^(.*)$ /folder/$1 [L]
then in order to hide joomla folder I add to joomla htaccess:
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.mydomain.com/$1/ [R=301,L]
RewriteCond %{REQUEST_URI} !^/folder
RewriteRule ^(.*)$ folder/$1 [L]
and next I change configuration.php file in joomla folder:
var $live_site = 'http://www.mydomain.com/';
It works.
Thanks a lot for your answers.
test it:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteCond %{REQUEST_URI} !^/path/to/folder/
RewriteRule ^(.*)$ path/to/folder/$1 [L]