Note, from some searching I see that it's also possible to achieve redirects with RewriteRule rather than Redirect but I'm still curious to know why my catch-all isn't working with Redirect.
What I'm doing is redirecting various links on my site to a series of third party pages, and then using a catch-all to catch anything that isn't currently available under the /help/ path:
<IfModule mod_alias.c>
Redirect 302 /help/abc https://example.com/help_pages/kKh6Sun7
Redirect 302 /help/efg https://example.com/help_pages/jGut20m3
# catchall...
RedirectMatch 302 /help/.* https://example.com/help_pages/default
</IfModule>
But even mysite.com/help/efg is being redirected to the catch-all. I thought that these directives were processed in order, since they are part of the same Apache module and in the same context... see here?
Related
I'm working on setting up a 301 redirect in an .htaccess file and I can get it to sorta work, but I'm not sure why it's not picking up on anything after a specific URL in the rewrite rule.
I currently have this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/old-path/page/(.*) /new-page/ [R=301,L]
</IfModule>
Which works fine if I test it with http://example.com/old-path/page which redirects to http://example.com/new-page
But if I try this:
http://example.com/old-path/page/test it will 404 and not redirect to http://example.com/new-page
Overall, since I'm not 100% if there are any other pages from the old path that may be nested within the page I want to make sure that I'm catching any of them and just redirecting to the new-path outright.
So, I'm not sure if I'm setting this up incorrectly or if there is something that I'm missing?
We want to redirect most , but not all, of a website wit a 301 redirect.
Will this work or is the first line to much ?
redirect 301 / http://designers-floor.nl/
redirect 301 /index.php http://designers-floor.nl/
redirect 301 /index.php/woonbeton http://designers-floor.nl/inspiratie/
The Redirect directive will redirect any url starting with the first fragment to the second fragment. The first directive will thus redirect the entire site. (docs)
I recommend testing with temporary redirects until you have accomplished what you want, because testing with permanent redirects will cause those redirects to be cached. Once everything works as expected you can make the redirects permanent. Make sure that the most specific url is always listed first, so that it is matched first.
If you cannot accomplish your goal with just the Redirect directives, you can either use RedirectMatch (docs) or the RewriteEngine of mod_rewrite (docs).
I'm having a problem getting an old WordPress site page to redirect to the new basic PHP site page.
Example: The old WordPress page with no extension is at http://example.com/levelone/leveltwo/pagename
The new page is at http://example.com/directory/pagename.php.
Here are several things I've tried:
redirect 301 /levelone/leveltwo/pagename http://example.com/directory/pagename.php
This did not work at all
Then I tried redirecting the directories first, then the page, like so:
RedirectMatch 301 ^/levelone/leveltwo/ http://example.com/directory/
redirect 301 /pagename http://example.com/pagename.php
This almost worked, but gave me the right URL but without the PHP extension.
I can't just redirect an old directory to a new one because there are actually many. The example is just one. The trouble seems to be going from a non-extension page to a page with the .php extension.
Here's another thing I tried:
RedirectMatch 301 ^/levelone/leveltwo/(.*)$ /directory/$1.php
redirect 301 /pagename http://example.com/pagename.php
This gave me http://example.com/directory/pagename/.php.
Solved: I got it to work with the following:
Redirect 301 /levelone/leveltwo/pagename/ http://example.com/directory/pagename.php
The problem seemed to be with the missing forward-slash after the old page name.
Try:
RedirectMatch 301 ^/levelone/leveltwo/(.*)$ /directory/$1.php
What's probably happening is the mod_alias and mod_rewrite aren't playing nice with each other. They're both in the URI-file mapping pipeline so when one does its processing, the URI (eventhough a redirect response is what's going to ultimately happen) continues to get processed, then when the redirect happens, the URI has been mangled by mod_rewrite.
You should just stick with mod_rewrite so that you can prevent any wordpress rules from doing its thing. Add these rules above any wordpress rules you have in your htaccess file:
RewriteEngine On
RewriteRule ^/?levelone/leveltwo/(.*)$ /directory/$1.php [L,R=301]
I'm having a problem with my htaccess, we've moved a website and they're old website had a lot of duplicate pages that had a ?cat_id=88 etc... on them, I'm trying to redirect the page but it's not working, I've put the redirect code below, I'm already redirection the mantra.html to the /Mantra but the version with the ?cat_id=79 isn't redirecting, it's just ignoring everything after the ?
Redirect 301 /mantra.html?cat_id=79 http://www.website.co.uk/Mantra
Redirect only accepts paths, not paths with querystring. You could use mod_rewrite
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat_id=79$
RewriteRule ^mantra\.html$ /Mantra? [R=302,L]
change 302 to 301 once you get it working (301 are aggressively cached by browsers and make debugging a nightmare).
EDIT added a ? at the end to remove any querystring. Apache removes the ? if there is no other data in the querystring, so the end user will never see it.
I couldn't find a straight answer to my question and need to know it from the real experts.
I had a website which urls were generated by Joomla. I believe that tons of urls are around in the search engines and I really don't know which of them all. A 302 redirect would be an option, but I can't say which urls need to be redirected.
The only thing I know that all the urls were generated by a sef404 script, it's a SEO script for Joomla.
My question, how can I make sure that all the orphan urls on google and other search engines are delivered correctly with a .htaccess file?
How do I 301 redirect all 404 pages to the homepage (root document)
At the moment I use a custom 404.html error file, but there are too many files and will give a rollercoaster of custom 404 error pages
I came up with the solution and posted it on my blog
http://web.archive.org/web/20130310123646/http://onlinemarketingexperts.com.au/2013/01/how-to-permanently-redirect-301-all-404-missing-pages-in-htaccess/
here is the htaccess code also
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
but I posted other solutions on my blog too, it depends what you need really
You will need to know something about the URLs, like do they have a specific directory or some query string element because you have to match for something. Otherwise you will have to redirect on the 404. If this is what is required then do something like this in your .htaccess:
ErrorDocument 404 /index.php
An error page redirect must be relative to root so you cannot use www.mydomain.com.
If you have a pattern to match too then use 301 instead of 302 because 301 is permanent and 302 is temporary. A 301 will get the old URLs removed from the search engines and the 302 will not.
Mod Rewrite Reference: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html