.htaccess RewriteRule not redirecting to the correct place - apache

We found hundreds of 404 in one of our blogs, the previous team, deleted a lot of tags and articles. We are trying to create a 301 that redirects anything with /blog/forums in on WP app to WP /knowledge a different WP.
We have many instances like
blog/forums/topic/native-property-window/
blog/forums/user/hemo2/
blog/forums/topic-tag/wql/
We need the redirect to work no matter whats after blog/forums
and redirect them to
/knowledge
Any suggestions?

To redirect anything starting with blog/forums/ to /knowledge is pretty simple
RewriteRule ^blog/forums/ /knowledge [R,L]

Related

Oscommerce to OpenCart Redirects

The way that Oscommerce SEO Friendly URLs work, is that they are generated from a product or category title followed by a p for product and c for category, then the product or category ID. For categories, each parent directory ID is also used.
for example:
https://example.com/jeep-pinion-gears-c-284_845.html
over the course of many years, products and categories get edited and moved therefore changing the URL. However, all the old URL's still resolved because pages are served strictly based off of the last part of the URL. It looks for the c or p and the ID's. SEO is still able to be maintained.
For Example:
https://example.com/jeep-pinion-gears-c-284_845.html
https://example.com/jeep-pinion-gears-and-accessories-c-284_845.html
https://example.com/jeep-pinion-gears-c-284_1234_845.html
https://example.com/ring-pinion-gears-c-845.html
Would all load the same content.
I've recently changed over to OpenCart where I used the latest URL for each product and category from the OsCommerce store. However, all the of Old Oscommerce URL's don't work.
I was originally writing some regex redirects to match the ID's but I'm running into redirect loop issues.
Does anyone any any ideas on a different approach?
If there is a way to derive the new OpenCart URL from your OsCommerce SEO URLs
RewriteCond %{REQUEST_URI} !^/.*?-[cp]-\d+\.html$
RewriteCond %{REQUEST_URI} ^/(.*?)-([cp])-[\d_]*?(\d+)\.html$ [NC]
RewriteRule (.*) https://new.example.com/%2-%3.php [R=301,L]
The important part here is the stop not rule to prevent looping redirects.
put it below others rewrites, removing a trailing slash or the www-subdomain, or http to https rewriting.
If three is no "simple relationship" between the two URLs you are out of luck and have to write a redirect for each of them. You should be able to generate the rules using the SEO URLs stored in the DB.
Redirect 301 /old-page.html http://www.example.com/new-page.html
Maybe a PHP redirect could be helpful too?
header("Location: http://www.example.com/new-page.html", true, 301);
exit();

htaccess 301 redirect for webshop transfer

I searched stackoverflow but couldn't find a solution that fits my need. On top of it, if must admit, that regex is a pretty difficult thing for me. So here is the thing:
I have a new webshop (domain-new.com) that has basically the same products of old shop (weird product urls, weird categories, everything weird, ...) but on a new technology, new domain and proper URLs. Thus, I would like to close the old shop and transfer the SEO rankings with a 301 redirect to the new domain/shop.
My solution is that the old shop/domain serves a .htaccess file with a lot of links:
RewriteEngine On
Redirect 301 / http://www.domain-new.com/ ###front page
Redirect 301 old-weird-product-path1 http://www.domain-new.com/new-product1.html
Redirect 301 old-weird-product-path2 http://www.domain-new.com/new-product2.html
Redirect 301 old-weird-product-path3 http://www.domain-new.com/new-product3.html
Redirect 301 old-weird-product-path4 http://www.domain-new.com/new-product4.html
I could manage to link about 300 products and categories but can't manage to do the hole list of 5000 products and categories.
Is there a way to add a line of code that says: "and for everything else, thats not listed above, redirect to the front page of the new webshop?
Thanks in advance and sorry, if the question was answered somewhere else. I couldn't find the proper solution.
This may be possible with regex match if you have a common pattern in weird urls.
Then Regex not match common url pattern and redirect to home page of new website something like
RewriteEngine on
RewriteRule [^old-weird-product-path] http://www.domain-new.com/ [R=301,L]
You may have to refine it as per url structure.

Drupal - Redirect just the homepage

due to internal politics with a project I need to redirect only the homepage of a site built in drupal to a different url. I want to be able to access the rest of the site to show people but just that when it goes to the homepage it redirects you.
I want to create a copy of the homepage and then have the original homepage automatically redirect to the new url....meta refresh wouldnt work because there is lag time...
Anyone know how to do this with .htaccess ?
Thanks
Add new comment
You can try adding this rule as first rule:
RewriteRule ^$ /new-home-page [L,R]

Proper 301 redirect for sites

I have a bit of a complex question. I am moving sites from
http://www.hikingsanfrancisco.com
to
http://www.comehike.com
The directory structures will not be the same throughout both sites. What are some of the best practice things I can do in order to retain most of my existing SEO strength in both the general domain and individual pages for searches related to the other pages?
Thank you,
Alex
If most of the URLs are staying the same and just the domain is changing, you could create an .htaccess file in the root folder at the old site with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.comehike.com/$1 [R=301,L]
This will make hikingsanfrancisco.com/some-page go to comehike.com/some-page.
Otherwise in that same htaccess file you could add a line for each redirect. So if hikingsanfrancisco.com/big-hikes is now going to comehike.com/even-bigger-hikes the redirect would look like:
Redirect 301 /big-hikes http://www.comehike.com/even-bigger-hikes
That 301 tells Google to now consider the new URL correct.
To redirect the whole site no matter what to the new URL you could use this:
Redirect 301 / http://www.comehike.com/
A 301 Redirect, page by page, is the best option (If you can use regular expressions is easier). Redirect the old page to a page in the new site with similar content.
Use the change of address tool in Google Webmasters tools.
Try to contact some of yours referrals to change the links that target your site.

Problems with mod_rewrite and 301 redirects from one dynamic url to another

Hey all, I'm having all kinds of problems with a bunch of apache redirects just now and could really use some help!
I'm wating to put in a 301 redirect for a load of urls from a client's old site to their new site in the following format;
Old - page.php?pageNum_rs_all=0&totalRows_rs_all=112
New - page/sub?foo=bar
The values in the query sting for the old site don't in any way tie up to any ids or references on the new site, I only want to match that specific request and redirect to the new page.
It feels like I've tried just about every combination of rewriterule I can find online but still nothing seems to be working. This is running on Apache 2.2.
The rule I started with (and keep going back to) is;
RewriteRule ^/page.php\?pageNum_rs_all=0&totalRows_rs_all=112 /page/sub?foo=bar [R=301,L,NE]
Any help would be greatly appreciated!
c.
The reason that this doesn't work is that RewriteRule can't see the QueryString. To get at the Query String, you need to use RewriteCond. See http://wiki.apache.org/httpd/RewriteQueryString for examples of how this works.
I've always tended to use use a series of 301 redirects in the following manner
Redirect 301 /oldpage /newpage