Is it possible to add code to the root htaccess file of a site, to direct all traffic to the main index page for the site? For example, if someone goes to any of the following URLs, they they should be redirected to example.com:
subdomain.example.com
example.com/directory
You may use these rules in site root .htaccess of example.com:
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !(?:jpe?g|gif|png|ico|tiff|css|js)$ [NC]
RewriteRule !^index\.html$ /index.html [L,NC,R]
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 a site in "example.com/a" and would like to redirect 301 just url "example.com/a" to "example.com/b" and other data in "example.com/a" dont change address.
create .htaccess in "example.com/a" and try using several code like:
RewriteEngine on
RewriteRule ^$ http://www.example.com/b [R=301,L]
and
RedirectMatch 301 ^/$ https://example.com/b
and its redirect root but all other data in "example.com/a" show 404 error.
I have a lot of photos in "root/a" , just want to redirect the "root/a" address to "root/b" and the address of the photos remains the same.
For example, the "root/ a/pic.jpg" address will remain unchanged before and after the redirect,
How can i just redirect the "example.com/a" and other old address not change?
If I understood you well you need to redirect root/a to root/b while maintaining location of the rest of the pages, files?
This will do:
# Redirect Root Only
<IfModule mod_rewrite.c>
RewriteEngine On
#Uncheck line below to redirect 'index.php' as well
#Redirect 301 /a/index.php http://example.com/b/
#Redirect root only
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/a/$
Rewriterule ^(.*)$ http://example.com/b/ [L,R=301]
</IfModule>
# END Redirect Root Only
Need to redirect index.php, index.html, or other index pages too? Uncheck the line in code above. Because %{REQUEST_URI} ^/a/$ excludes all direct file paths including /a/index.html,index.php,index.py,etc.
How do I create a redirect so that http://fullurl/store redirects to
https://fullurl/store
Do I do this in htaccess or robots?
Thanks for your help
robots.txt is used only for telling search engine bots and other crawlers how to deal with your URL structure, it has nothing to do with redirecting the user.
To force HTTPS on a site, add the following to the .htaccess file in the web root of fullurl (or inside the root of store to redirect only that directory to HTTPS):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I'm trying to redirect this URL to a different subdomain but am getting a 404.
Need to redirect:
www.dustystrings.com/instrumentbuilding / XYZ
To here:
manufacturing.dustystrings.com/instrumentbuilding / XYZ
I have www.dustystrings.com on one server, and manufacturing.dustystrings.com on another server (necessity).
Basically, I want to redirect all www.dustystrings.com/instrumentbuilding/ queries to manufacturing.dustystrings.com/instrumentbuilding/
What's the right .htacess 301 code to do this? (Apache server)
This should work:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.dustystrings.com[nc]
RewriteRule ^.*/instrumentbuilding/(.*)$ http://manufacturing.dustystrings.com/instrumentbuilding/$1 [r=301,nc]
Redirect to www using htaccess redirect
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
I want to redirect users to another domain name when they visit a certain directory in my website. For example; if the user visits /files then it would redirect them to www.myfiles.com. However, I would also like to do the same with subdomains so that when the user goes to /files or files.domain.com they are redirected to www.myfiles.com, for example.
How can I do this in a .htaccess file?
I hope people can understand what I am trying to describe.
use this
Redirect 301 /files http://www.myfiles.com
Try adding the following to the .htaccess file in the root directory of your domain.com site.
RewriteEngine on
RewriteBase /
#if either files.domain.com
RewriteCond %{HTTP_HOST} ^files\.domain\.com$ [NC,OR]
#or /files
RewriteCond %{REQUEST_URI} ^/files$ [NC]
#redirect to www.myfiles.com
RewriteRule ^ http://www.myfiles.com [L,R=301]