.htaccess 301 re-directing .html pages to sitemap.html - .htaccess

I've tried 301 redirecting .html pages to sitemap.html in two ways and neither one works.
I've checked this code over and over again.
I've used .htaccess checkers/validators and they show no errors.
The same code works for folder-to-folder re-directs--this only happens for re-directs from .html files to sitemap.html.
The Problem:
The pages should be redirected to www.example.com/sitemap.html
Instead they're redirected to www.example.com/sitemap.htmlpage.html
In other words, .htaccess somehow puts the file name after sitemap.html.
I've used these two methods:
1:
RewriteRule ^directory/(.*)$ /sitemap.html$1 [R=301,NC,L]
In the first one, all the files within the directory should be re-directed to sitemap.html. Note that the index page of the category re-directs fine but the .html ending pages inside it don't.
2:
redirect 301 /directory/page.html http://www.example.com/sitemap.html
I've also tried redirecting each page individually with the same results.
Any idea what's wrong here?

You should not use captured for redirecting everything to /sitemap.xml. Just use a rule like this in root .htaccess:
RewriteEngine On
RewriteRule ^directory/ /sitemap.html [R=301,NC,L]

Related

.htaccess RewriteRule Redirect works on htaccess tester, does not work on server

I have an .htaccess file defined at www.mydomain/documentation/.htaccess and am trying to redirect a number of broken links to a specific page.
The .htaccess file contains the Rewrite Rule
RewriteRule ^/?(documentation/PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]
Note: RewriteEngine ON has already been defined. Other rules are being applied
Now in .htaccess tester the rule is being evaluated and redirects correctly when the following URL is requested:
www.mydomain.com/documentation/PresentationCore~System.Windows.RoutedEventArgs~Handled.html
However, when the same domain is entered into the browser, I get a 404 not found for this page.
I can confirm I have uploaded .htaccess to the correct folder and cleared the server cache.
Is there anything else I need to do to get this to work?
You dont need to match the folder name if htaccess is already in that folder, try :
RewriteRule ^/?(PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]

Redirect only a single folder to a new website

I'm trying to redirect an old part of my website to a new website. This part is contained in a folder, http://example.com/infos/.
All pages or subfolders should be redirected to the homepage of the new website,
http://www.new-website.com/
e.g.
http://example.com/infos/ redirects to http://www.new-website.com
http://example.com/infos/test.html redirects to http://www.new-website.com
http://example.com/infos/sub/hello.html redirects to http://www.new-website.com
However I don't want to redirect
http://example.com/
http://example.com/geo.html
http://example.com/test/1.html
I tried the following declaration on a .htaccess file, but it didn't work.
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^infos/(.*)$ http://www.new-web-site.com [R=301,NC,L]
</IfModule>
Could you help me please?
Option 1
This one depends on who you are using to host your website. There might be a redirects button that takes you to a page to add a redirect. You could redirect the whole site (e.g. anything starting with http://example.com/) or just certain folders on the site.
Option 2
Place a file called .htaccess in http://example.com/(root folder) with the following contents:
RedirectMatch 301 ^/my_redirected_folder/ http://www.new-website.com/

How to redirect a specific page using htaccess

I've looked all over for the htaccess code to redirect a single page and haven't had any luck with many solutions.
Basically I need to redirect this:
/example/my-stuff/
to:
/example/home/
but I don't want any other pages except for /my-stuff/ to be redirected. Eg. these pages should not be redirected and kept the same.
/example/my-stuff/a-page
/example/my-stuff/anything
In the htaccess file in your document root, you can add either this:
RedirectMatch 301 ^/example/my-stuff/$ /example/home/
Or you can use mod_rewrite instead:
RewriteEngine On
RewriteRule ^example/my-stuff/$ /example/home/ [L,R=301]

Problems with htaccess Redirect (Page on one domain to same page on another)

I'm trying to redirect a few pages to a new domain and I have done this before but for some reason I can't get the code to work.
RewriteEngine On
Redirect 301 http://domain.com/page1.html http://domain2.com/page1.html
Can anyone see where I'm going wrong?
In .htaccess file the below code will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Since you say you only want to direct a FEW of your pages and not all of them, you can do:
RewriteEngine On
Redirect /~myaccount/oldpage.html http://www.newsite.com/newpage.html
You specify the path to the page on your current server followed by the URL to redirect to.
OR you can do:
RedirectMatch 301 ^/oldpage\.html$ http://www.newsite.com/newpage.html

Help with 301 redirect (Simple concept, per directory control)

I'm trying to get a set of 301 redirects working for a client site, and I'm getting a bit stuck.
I have about 17 different directories that have .html content fileswhich I am moving across to Wordpress. What I am trying to do is create a simple, single .htaccess file with redirects in that will allow me to redirect all the .html files within a directory to wordpress URLs without an extension:
Manual redirect example:
redirect 301 /blog/2009/04/post1.html /blog/2009/04/post1/
redirect 301 /blog/2009/04/post2.html /blog/2009/04/post2/
Trying to create a rule like:
RewriteRule ^/blog/2009/04/(.*?).html$ /blog/2009/04/$1/ [R=301,NC,L]
Where the $1 is the filename (minus the .html) suffixed with a /
I can't determine whether the ^/blog/2009/04/(.*?).html$ means it will only redirect for this particular directory, and will redirect to the right location.
I would obviously want to duplicate this ReWriteRule for all my designated content directories...
Can anyone point me in the right direction?
Thanks,
Lee
Yes, your rule will only redirect for the 2009/04 directory. I think you want:
RewriteRule ^/blog/([0-9]+)/([0-9]+)/(.*?).html$ /blog/$1/$2/$3/ [R=301,NC,L]
This will now also redirect /blog/2008/12/post.html to /blog/2008/12/post/ and so on. Although since you have almost exactly the same format, maybe this will be easier?
RewriteRule ^/blog/(.*?).html$ /blog/$1/ [R=301,NC,L]

Resources