I have several domain aliases pointing to the same website like:
domain1.de/en/
domain1.de/de/
domain2.ch/de/
domain2.ch/en/
When someone opens a specific language-based sub-directory on a URL, I would like to redirect them to the start page, e.g. for domain1.de users shouldn't be able to access the sub-directory /en/ but be redirected to the start page. For the domain2.ch users should only have access to the directory /en/ and not /de/. How can I set this up with Htaccess?
This might be a helpful link to you;
htaccess redirect
for a 301 redirect entire directory it generated the following code:
//301 Redirect Entire Directory
RedirectMatch 301 domain2.ch/de/(.*) domain2.ch/en//$1
RedirectMatch 301 domain1.de/de/(.*) domain1.de/en//$1
Give this a try:
RewriteCond %{HTTP_HOST} ^de\.domain\.de$ [NC]
RewriteCond %{REQUEST_URI} ^(.*)/en/(.*)$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/targetpage.php [R=301,L]
Related
I'm on a subdomain and only want to redirect from this subdomain shop.example.com to example.com, but I want all other urls from shop.example.com still to work and be kept. Like shop.example.com/checkout should not be affected by this rule only /
In the subdomain directory shop.example.com I tried this in .htaccess
Redirect 301 / https://example.com
But then all is redirected
Try with below rule, I am using mod_rewrite.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shop\. [NC]
RewriteRule ^$ http://example.com [R=301,L]
I have re-vamped a website and I'm attempting to ensure all of the old, deleted directories are redirected to the new pages. For example, I have a directory called /category/ and want it redirected to http://website.com/interiordesign.html. The root website is still the exact same. I've implemented some coding in the .htaccess file, but it is giving me a redirect error.
Here is my code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]
Redirect 301 /category/ http://website.com/interiordesign.html
Redirect 301 /interior-design-portfolio/ http://website.com/interiordesign.html
Redirect 301 /contact-location/ http://website.com/contact.html
Redirect 301 /tag/ http://website.com/blog.html
I have the remove / rule in place, as I found when I didn't implement that, it was taking the user to interiordesign.html/ and with the slash, it didn't work.
Apologies for my poor coding, this is not my area of expertise.
I am trying to create a permanent htaccess redirect (301) from all files in one directory in one domain, to another domain sub-directory as follows:
Redirect all files in the following directory:
from: www.xxx.com/apps/forms/reg.html
to: www.yyy.com/apps/forms/reg.html
if someone entered the first url it should redirect to the second url
Please help on this to fix my redirection issue
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain1.extension$ [NC]
RewriteRule ^(.*)$ http://domain2.extension$1 [L,R=301]
I want to be able to use an .htacess file to allow the main domain only to be redirected, but not a subfolder of that domain.
Example; somesite.com redirects to something.somesite.com
but allow somesite.com/example through to what is in the /example directory.
I did see a question similar to this one but could not understand the answer well enough to want to use the code.
Try adding this to the htaccess file in somesite.com's document root:
RedirectMatch 301 ^/$ http://something.somesite.com/
Of if you'd rather use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} somesite\.com$ [NC]
RewriteRule ^/?$ http://something.somesite.com/ [L,R=301]
I should do internal redirects (301) for the list of pages.
Firstly when user opens / or /index.php he should be redirected to em.php, places in root folder. When user opens /contents/about_us/index.php he should be redirected to about_us/enterprise.php
Sound simple but I still can't to solve
When I use this
Redirect 301 / http://foo2.bar.com/service
Redirect 301 /index.php http://foo2.bar.com/service
it works.
But when I try this
Redirect 301 / http://www.site.com/em.php
I'm getting http://www.site.com/em.phpem.phpem.phpem.phpem.phpem.phpem.phpem.phpem.php ...
What's wrong with my code?
Your Redirect is going into a loop.
Do this instead either in a .htaccess file in DocumentRootor in your virtualhost section.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule ^ /em.php [L,R=301]