we're migrating domains and some but not all content. The URL structure is different.
Below is what I have in my .htaccess file. I only added the code at the end starting with "#User added 301 Redirect", the other entries were in .htaccess already.
Expected/Desired: I want anyone who goes to the old main domain to the new main domain, and anyone who attempts to access these specific pages of the old site/domain to go to the mapping in the new site.
Observed: the main domain 301 works olddomain.com now goes to newdomain.com, or if the file name/path is exactly the same. Redirects follow he taxonomy of the old domain, not use my mapping. So, "olddomain.com/about-me" tries to go to "newdomain.com/about-me" instead of the correct mapping "newdomain.com/about" as shown in the .htaccess file and results in a 401 file not found error.
Thoughts? Feel free to respond like I'm five years old.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
AddHandler x-mapp-php5.5 .php
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Wordfence WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END Wordfence WAF
# User Added 301 Redirect
Redirect 301 / https://newdomain.com/
Redirect 301 /paleo-salmon-cakes https://newdomain.com/blog-entries/paleo-lemon-ginger-salmon-cakes
Redirect 301 /organic-vs-conventional https://newdomain.com/blog-entries/organic-vs-conventional-produce
Redirect 301 /endocrine-disruptors https://newdomain.com.com/blog-entries/what-are-endocrine-disruptors-and-why-you-should-care
Redirect 301 /vegan-paleo-caesar-dressing https://newdomain.com/blog-entries/avocado-cashew-caesar-salad-dressing-vegan-and-paleo
Redirect 301 /about-me https://newdomain.com/about
Redirect 301 /contact https://newdomain.com/contact
Redirect 301 /work-with-me/business-client-services https://newdomain/for-businesses
Redirect 301 /work-with-me/individual-client-services https://newdomain.com/for-individuals
Redirect 301 /work-with-me/pregnant-postpartum https://newdomain.com/for-individuals
Redirect 301 /spinach-banana-muffins https://newdomain.com/blog-entries/spinach-banana-muffins
# User Added 301 Redirect
You could try redirect directives in following order:
# User Added 301 Redirect
#Redirect 301 / https://newdomain.com/
Redirect 301 /paleo-salmon-cakes https://newdomain.com/blog-entries/paleo-lemon-ginger-salmon-cakes
Redirect 301 /organic-vs-conventional https://newdomain.com/blog-entries/organic-vs-conventional-produce
Redirect 301 /endocrine-disruptors https://newdomain.com.com/blog-entries/what-are-endocrine-disruptors-and-why-you-should-care
Redirect 301 /vegan-paleo-caesar-dressing https://newdomain.com/blog-entries/avocado-cashew-caesar-salad-dressing-vegan-and-paleo
Redirect 301 /about-me https://newdomain.com/about
Redirect 301 /contact https://newdomain.com/contact
Redirect 301 /work-with-me/business-client-services https://newdomain/for-businesses
Redirect 301 /work-with-me/individual-client-services https://newdomain.com/for-individuals
Redirect 301 /work-with-me/pregnant-postpartum https://newdomain.com/for-individuals
Redirect 301 /spinach-banana-muffins https://newdomain.com/blog-entries/spinach-banana-muffins
#
# this as the last line:
#
Redirect 301 / https://newdomain.com/
# User Added 301 Redirect
Related
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.
Hi I am new to redirects.
I can get the basic Redirect 301 /page1/ https://example.com/newpage/ redirects to work fine.
I am having an issue with removing a parent page and all of it's child pages and redirecting everything to a new parent page.
The main redirect works:
Redirect 301 /eye-can-hear/ htps://example.com/procedures-services/
But trying to redirect the sub pages
Redirect 301 /eye-can-hear/hearing-services/ https://example.com/procedures-services/
Is redirecting to /procedures-services/hearing-services/ which doesn't exist.
Here is what the .htaccess file looks like, the 2-7 do not redirect properly:
Redirect 301 /eye-can-hear/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/hearing-services/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/hearing-aids/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/self-test-your-hearing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/schedule-your-hearing-evaluation/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/financing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/dual-sensory-wellness/ https://example.com/procedures-services/
Redirect 301 /about-costello-eye-physicians/community-involvement/ https://example.com/about-costello-eye-physicians/in-the-news/
There are some more redirect's but I can only post 7 links. Further down the .htaccess file after some iThemes security stuff is this:
# Stop wordpress username enumeration vulnerability
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^/?author=([0-9]*)
RewriteRule ^(.*)$ https://example.com/? [L,R=301]
and also this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Change this lines (2-7) that do not redirect properly to this rewrite:
RewriteEngine On
RewriteRule ^eye-can-hear\/(.*)$ https://example.com/procedures-services [R=301,L]
It's redirect all subpages of /eye-can-hear/* to https://example.com/procedures-services
This line of code worked for me in the .htaccess file:
RedirectMatch 301 /eye-can-hear/(.*) https://example.com/procedures-services
It redirects the page https://example.com/eye-can-hear/ and its subpages to the URL https://example.com/procedures-services
(Answer after two years, but maybe it helps someone)
In the htaccess file, you should put this redirection after all other redirections of subpages:
Redirect 301 /eye-can-hear/ https://example.com/procedures-services/
Your htaccess should be like this:
Redirect 301 /eye-can-hear/hearing-services/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/hearing-aids/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/self-test-your-hearing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/schedule-your-hearing-evaluation/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/financing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/dual-sensory-wellness/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/ https://example.com/procedures-services/
I am having an issue with my 301 redirects.
I just upgraded my site from an html based site to a joomla site. SO I am trying to redirect the 50 or so pages to the new joomla based navigation.
SO what is working:
rewrite rule to remove index.php, and the www., and 301 redirects
What isn't working:
301 redirect with a www in front of it.
www.sample.com/page.html
It sends them to the home page instead of the page, it takes them to the home page.
Here is my www rewrite rule.
## Redirects to www.
RewriteEngine On
RewriteCond %{HTTP_HOST} www.sample.com
RewriteRule (.*) http://sample.com/$1 [R=301,L]
Here is my 301 rule
Redirect 301 /page.html /page
Thanks for the help.
If you are trying to remove the www then you might want to change the matching up some. Try your rule like this.
## Redirects to www.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.sample\.com$ [NC]
RewriteRule (.*) http://sample.com/$1 [R=301,L]
RewriteRule ^page.html$ /page [R=301,L]
RewriteRule ^page2.html$ /page2 [R=301,L]
I've been asked to redirect two pages to a different url. It's working except I get a trailing backslash at the end of the url due to the existing WP rewrite rules. I need to redirect these pages, but leave the WP rules intact for the pages that don't redirect.
Here are the existing WP rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to add:
Options +FollowSymLinks
RewriteEngine on
Redirect 301 /*old url* http://*new url*/about.html
Redirect 301 /*old url* http://*new url*.com/tour.html
When I do this it redirects to:
new url.com/tour.html/
and the trailing backslash is causing the problem
I am a total .htaccess novice.
Thanks,
Matt
This is a case with mod_alias and mod_rewrite interfering with each other because they are both part of the URI-file mapping pipeline, so once mod_alias does its thing (the Redirect directives) and flags the URI to be redirected, mod_rewrite then does its thing and rewrites the URI. So at the end of the URI-file mapping pipeline, you've got a 301 redirect but the URI got mangled by mod_rewrite.
You can just stick with mod_rewrite instead and make it so the wordpress rules don't get applied at all. You also need to add your redirects before your wordpress rules, so before the # BEGIN WordPress add:
RewriteEngine On
RewriteRule ^/?old_url http://new_url/about.html [L,R=301]
RewriteRule ^/?old_url2 http://new_url/tour.html [L,R=301]
I have a list of 301 Redirects like this inside htaccess:
Redirect 301 /oldpage1.php http://www.domain.com/newpage1.php
Redirect 301 /oldpage2.php http://www.domain.com/newpage2.php
Redirect 301 /oldpage3.php http://www.domain.com/newpage3.php
...
Now these pages shall be redirected only for a certain domain (there are other domains now pointing to the same location like www.domain.com).
E.g. www.domain.com/oldpage1.php shall be redirected, but www.sub.domain.com/oldpage1.php not.
So whats the way to apply these redirects only for www.domain.com?
Thanks.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^oldpage1\.php/?$ newpage1.php [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^oldpage2\.php/?$ newpage2.php [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^oldpage3\.php/?$ newpage3.php [L,R=301]
PS: If you have several rules like above then it is much better to use RewriteMap.