I have a .htaccess that is supposed to do the following:
Redirect URLs from old Website to new pages
Redirect to custom 404 page if file is non-existent
This is my Code:
Redirect 301 /oldpage.php /newpage
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ - [L,R=404]
ErrorDocument 404 /404
My problem is: The redirect does not go to /newpage instead queries to /oldpage.php are redirected to /404
Thanks for your help!
//Custom 404 errors
ErrorDocument 404 /path/to/custom/404.php
//301 Redirect from a specific Old File to new
Redirect 301 /oldpage.php /newpage.php
//301 Redirect from a different URL path
Redirect 301 /posts http://mywebsite.com/blog
//301 Redirect from an old directory to a new directory
RedirectMatch 301 /old-directory/(.*) /new-directory/$1
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 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 changed nearly all of the page names on my web site. No actual files or pages were deleted. I implemented a complete set of RewriteRule 301 redirects in .htaccess for all the old page names to the new page names. This all worked perfectly.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html)$ http://www.domain.co.uk/$1 [R=301,L]
RewriteRule ^old-page-name.html$ http://www.domain.co.uk/new-page-name.html [R=301,L]
I have since created a 404.html page to catch traffic for incorrectly addressed backlinks and user typos in browser address bars, and implemented the relevant code in .htaccess to redirect incorrect URLs to my 404 page, after the 301 code above. This works, so if I try to access /ljdshfkkej.html, the /404.html page is displayed.
ErrorDocument 404 /404.html
However, now this above 404 rule takes precedence over my 301 rules, so if someone tries to access /old-page-name.html, they no longer are redirected to /new-page-name.html but instead to /404.html. This isn't ideal but could be worse.
Is it possible to keep the 404 rule but to only have it activated for URLs that do not exist but for which there is no 301 redirect for? Or is it a case of either or?
Here is an overview of the entire code.
# .htaccess file last updated 2016/07/22
RewriteEngine on
# redirect index.html/php to root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html)$ http://www.domain.co.uk/$1 [R=301,L]
# redirects from old pages
RewriteRule ^aboutus.html$ http://www.domain.co.uk/about-us.html [R=301,L]
RewriteRule ^ammonia-test-kits-brand.html$ http://www.domain.co.uk/ammonia-test-kits.html [R=301,L]
RewriteRule ^arsenic-free-fluoride-testing-brand.html$ http://www.domain.co.uk/fluoride-test-kit.html [R=301,L]
# 404 error - page not found
ErrorDocument 404 /404.html
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]