redirect old pages to new seo targets - .htaccess

i have a litte problem :(
on my site i created with mod_rewrite some rules...
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([0-9][0-9][0-9][0-9][0-9][0-9][^/]+)$ /index.php?lang=$1&i=$2&cat=$3&item=$4 [L]
with that rule i recieve the following link
/en/article/category/item/021205
with this code above is everything ok..
now my problem is that i changed my site for SEO.
the link looks now like this
/en/article/category/item/021205-seo-link-is-here
my problem are the pages in google and co..
is there a way to create rule that i can redirect:
/en/article/category/item/021205 >> to >> /en/article/category/item/021205-seo-link-is-here
my site is multilangual /en /es /fr if it is important for the rule
best regards bernte

If your want to do the redirect for each page on your own, then the order of your RewriteRules is important.
Better solution would be to ignore the seo-link in your index.php unless the articleId is unique

Related

Htaccess and redirect all content of folder, but exlude the main folder

I got the following urls:
domain.com/categoryA/articleA
domain.com/categoryA/articleB
I want to redirect:
domain.com/categoryA/articleA -> domain.com/categoryB/articleA
domain.com/categoryA/articleB -> domain.com/categoryB/articleB
but leave it as it is and do not redirect the main folder: domain.com/categoryA/
I tried to use the rule:
RewriteRule ^categoryA/(.*)$ /categoryB/$1 [R=301,NC,L]
but it also redirect domain.com/categoryA/ to domain.com/categoryB/
How to exclude from the above rewrite rule the redirection of the main folder (categoryA), but still redirect all that is in the folder (and then change also the root folder)?
I am looking for a solution that is SEO friendly (I got the same articles in two categories, but want still to have indexed domain.com/categoryA, but the rest only as domain.com/categoryB/xxx.
Best Greetings,
Mat
With your shown samples/attempts, please try following Rules in your .htaccess file. Please make sure to place this rule under your domain redirect rule(if its there), also make sure to clear your browser cache before testing your URLs.
RewriteRule ^categoryA/([\w-]+)/?$ /categoryB/$1 [R=301,NC,L]

Redirecting /folder/ to /file.html in magento

We published an article in the magazine with following url:
http://magnetic-sleep-machine.com/moves
Now we need to make sure when people put that URL they land to
https://magnetic-sleep-machine.com/moves.html
Please help me figure this out! .htaccess or use a magento (1.7) option?
There's a way to redirect using magento, but not sure if that's exactly what you want.
You could also try turning on multiviews, and let mod_negotiation take cure of fuzzy URL-file mapping, in your htaccess file:
Options +Multiviews
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^moves/?$ /moves.html [L,R=301]
Or using mod_alias:
RedirectMatch 301 ^/moves/?$ /moves.html
Okay I found the way to do it using magento itself.
created a new Page
page link named as "moves"
added javascript for redirect to body of the page
next went to system>config>web>
set Auto-redirect to Base URL to NO
Voila, it works now.

forcibly redirect to correct folder

I am new in htaccess.
I updated some SEO pages in my live site after one day some Url changes came so i changed the url again. but google already indexed it. So i want if some one found old url it will redirect to new url But in case of SEO pages only not for other pages.It means it wont affect to any other place.and there are not one page(it is 40-50 pages) can anybody give answer through htaccess or cakephp.
Old Url-
www.testenergy.com/test-energy-reviews
new url-
www.testenergy.com/s/test-energy-reviews
And there are also four senario-
www.testenergy.com/test-energy-reviews
www.testenergy.com/Test-Energy-Reviews
www.testenergy.com/s/test-energy-reviews
www.testenergy.com/s/Test-Energy-Reviews
All these four links will redirect to www.testenergy.com/s/test-energy-reviews Url only
Assuming you have mod_rewrite rules somewhere, you probably want to stick to mod_rewrite. You'll need to add these to the htaccess file in your document root, preferably above any other rules that are there:
RewriteEngine On
RewriteRule ^/?test-energy-reviews$ /s/test-energy-reviews [L,NC,R=301]
RewriteRule ^/?s/Test-Energy-Reviews$ /s/test-energy-reviews [L,R=301]
The NC flag ignores case, so it covers both /test-energy-reviews and /Test-Energy-Reviews. The second rule takes care of /s/Test-Energy-Reviews
I'm not sure why /s/test-energy-reviews (3rd one) is one of your scenarios, since it is exactly what you want to redirect to.
Try This ..!!
Router::redirect('/test-energy-reviews', 'http://www.testenergy.energy/s/test-energy-reviews');
write this line in Controller.
/********* Redirect Url fo small letter if some one type in uppercase in url bar****/
preg_match( '/[A-Z]+/',$this->params->url, $upper_case_found );
if(count($upper_case_found)) {
// Now redirect to lower case version of url
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . ROOTPATH.strtolower($this->params->url) );die();
}
/**** End Code******/
OR in htaccess write following code:
RewriteEngine On
RewriteRule ^/?test-energy-reviews$ /s/test-energy-reviews [L,NC,R=301]

.htaccess redirects - updated site (301 appropriate?)

I've run into a problem updating my site, the google search results show up links to the old page which are 404's now, some of them even containing deprecated content.
My question is about the use of 301's. The old page had deeply nested pages like the example below:
www.site.com/category/subjects/subject_b.html
It shows up in google with a very specific description of 'subject_b', which is not optimal for my purposes.
The new layout I've been working on means that content that was once under '/category/subjects/subject_b' is now found in a single page (www.site.com/subjects.html), along with the hypothetical subject_a & subject_c.
Would I be wrong redirecting the old pages like this?
redirect http://www.site.com/category/subjects/subject_a.html http://www.site.com/subjects.html
redirect http://www.site.com/category/subjects/subject_b.html http://www.site.com/subjects.html
redirect http://www.site.com/category/subjects/subject_c.html http://www.site.com/subjects.html
Also, how would I deal with pages that have google descriptions with content which is not on the new equavilient page?
I'd be happy if anyone could shed some light on this for me, or point me in a right direction as to where I can read more about it!
Would I be wrong redirecting the old pages like this?
You'd remove the http://www.site.com part. This should suffice:
Redirect 301 /category/subjects/subject_a.html /subjects.html
Redirect 301 /category/subjects/subject_b.html /subjects.html
Redirect 301 /category/subjects/subject_c.html /subjects.html
Or even:
RedirectMatch 301 ^/category/subjects/subject(.*) /subjects.html
to cover for all 3.
If you have multiple domains all pointing to the same document root and you actually need to match the path for a specific domain, you can use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?site.com$ [NC]
RewriteRule ^/?category/subjects/subject(.*) /subjects.html [L,R=301]

.htaccess Rewrite Based on Existence of Path in URL

Here's the scenario, I have a website that used to be a static HTML site and WordPress blog using a subdomain (http://blog.domain.com).
I recently combined everything into a single WordPress installation. To maintain old links I had to rewrite requests like "http://blog.domain.com/index.php/2010/10/16/post-name" to "http://domain.com/index.php/2010/10/16/post-name". My problem is that when trying to visit just "http://blog.domain.com", I get redirected to "http://domain.com" when I want it to go to "http://domain.com/index.php/blog".
So, if a user requests "http://blog.domain.com" (by itself, with or without slash), I want it to go to "http://domain.com/index.php/blog". If they request an old URL of "http://blog.domain.com/some-link-to-a-post", I want it to redirect to "http://domain.com/some-link-to-a-post". In other words, if it's a URL to an actual post, I just want to strip the "blog" subdomain. If it's the old link to the main blog page, I want to remove the "blog" subdomain and append "/index.php/blog"
http://blog.domain.com/ -> http://domain.com/index.php/blog
http://blog.domain.com/index.php/2010/10/16/post-title -> http://domain.com/index.php/2010/10/16/post-title
Hopefully that's clear. I'm not an htaccess expert, so hopefully someone can help me out here. Thanks in advance!
Using the [L] command at the end of a rewrite will tell htaccess that this is the last rule it should match. If you put a rule to match your first condition at the top and the other rewrite rule you said you had already created after it, you should get your expected result.
Try this:
RewriteRule ^blog.domain.com(/?)$ domain.com/index.php/blog [L]
# Your other rewrite here #
I couldn't get that solution to work. However, I used the following:
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/index.php/blog/$1 [R=301,L]
That ends up in a URL like http://domain.com/index.php/blog/index.php/2010/06/04/post-title, but Wordpress is smart enough to fix it.

Resources