Magento multi language rewrites SEO fix? - php

I have made a website in with Magento in one language 2 years ago and now I would like to add another language.
My actual structure is like that
example.com/category/
example.com/about.html
example.com/product.html
and I would like to obtain a structure like this:
example.com/lang1/category/
example.com/lang1/about.html
example.com/lang1/product.html
example.com/lang2/category/
example.com/lang2/about.html
example.com/lang2/product.html
This is not a big deal since Magento allowes me us to do that simply logging in the backend ->System -> Configuration -> Web -> Add store code to Urls (YES)
I can't do this setting right now because before that I need to fix and do rewrites from the first structure to the new one.
example.com/everything_without_the_/lang1/_path to a permanent
example.com/lang1/everything
I need for example that the urls from the backlinks from posts from the socials and other webistes won't get a 404 error but will automatically be redirected with a 301 redirection to the equivalent page in the new structure.
So I would like to add a script like this in the natural language:
rewrite permanently all the urls which ends not with /lang1/ or /lang2/ to urls with the prefix /lang1/
I know that I could manually add rewrite rules with this schema in the Magento backend but I would prefer to know if it is possible to batch this directly from the database or with some script in the .htaccess or index.php and above all which one between these solutions will have a less negative impact in SEO and SERP.
I've found a solution
Hi I've found a solution:
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/it/
RewriteCond %{REQUEST_URI} !^/en/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteRule ^(/)?$ it/index.php [L]
at a first look works, but I not guarantee.
I hope this will help
Cheers

Try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/lang1/
RewriteCond %{REQUEST_URI} !(.*)/lang2/
RewriteRule ^(.*)$ http://www.domain.com/$1/lang1/ [R=301,L]

you can use .htaccess 301 url to make if possible with your own regex function
As you need some specific requirement to do with your language part
here i am giving you category example
Redirecting Subcategory URL with New Parent URL
Examples:
category/sub1 redirect to cat/sub1
category/sub2 redirect to cat/sub2
category/sub3 redirect to cat/sub3
This may be needed if you changed a parent Category URL or even if you want to remove the parent URL completely:
RewriteRule ^category/(.*) http://www.yourwebsite.com/cat/$1 [R=301, L]
OR to remove '/category/' completely from yourwebsite.com/category/sub and end up with yourwebsite.com/sub ('sub' can be any url):
RewriteRule ^category/(.*) http://www.yourwebsite.com/$1/ [R=301, L]
And also you can refer
http://www.learnmagento.org/magento-tutorials/301-redirects-in-magento/
http://blog.maximusbusiness.com/2012/10/magento-url-rewriting-regex-and-301-redirects-tips/
hope this will sure help you.

I've found a solution
Hi I've found a solution:
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/it/
RewriteCond %{REQUEST_URI} !^/en/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteRule ^(/)?$ it/index.php [L]
at a first look works, but I not guarantee. I hope this will help Cheers

Related

Rewrite Url at my website but my index on sub folder

I've been crawling forums for about 2 hours and still haven't found the solution to my problem so I am turning to you guys for help.
My URL looks like this
http://sevalinmutfagi.com/list.php?id=1?kategori=borekler
I want it to look like this
http://sevalinmutfagi.com/tarifler/borekler
I try so much rewrite example but my index file at a subfolder in /View/ so I can't rewrite my URLs
here my .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?sevalinmutfagi.com$ [NC]
RewriteCond %{REQUEST_URI} !^/View/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /View/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?sevalinmutfagi.com$ [NC]
RewriteRule ^(/)?$ View/index.php [L]
This code works well for redirect subfolder all pages but I try to add rewrite URL codes can't work. I hope that has been revealing. Thanks to every for help.
that's worked for me fine.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ /subfolder/$1 [NC,L]
The FIRST thing to learn about mod_rewrite is when NOT to use it. Since mod_alias handles your specific task very nicely, that’s what I’d use:
Redirect 301 / /subfolder/
Since that looks like it would be “loopy,” you could fall back on mod_rewrite:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^subfolder/
RewriteRule .? subfolder%{REQUEST_URI} [R=301,L]
There’s just too much wrong with your attempt to cover … and I’ve addressed exactly those issues many times in many threads. Therefore, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too

Simple mod rewrite query string but still failed

I want to create .htaccess mod rewrite but still have problem.
Suppose i created friendly URL like this :
mydomain.com/mypage/12345/title-of-news
I want that friendly URL process the below URL in hidden process :
mydomain.com/index.php?p=mypage&idnews=12345
Values of "p" and "idnews" are dynamic, so they will have different value.
I tried below code but still didn't work. Anything wrong?
RewriteBase /
RewriteCond %{QUERY_STRING} p=(\w+)&idnews=(\d+)
RewriteRule ^index.php /%1/%2 [L,R=301]
Any help would be appreciated. Sorry if this is duplicated question, if don't mind please tell me the answer link. Thanks a lot.
I think you don't need the RewriteCond you write there.
And you can use following rule
RewriteRule ^/?([0-9a-zA-Z_.-]+)/([0-9]+)/([0-9a-zA-Z_.-]+)$ index.php?p=$1&idnews=$2 [L]
If you want to change index.php?p=foo&idnews=bar to /foo/bar , try theses rules :
RewriteEngine on
##externally redirect "/index.php?p=foo&idnews=bar" to "/foo/bar"##
RewriteCond %{THE_REQUEST} /index\.php\?p=([^&]+)&idnews=([^&\s]+) [NC]
RewriteRule ^ /%1/%2? [L,R,NC]
##internally redirect "/foo/bar" to "/index.php?p=foo&idnews=bar"##
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?(.*)?$ /index.php?p=$1&idnews=$2 [NC,L]

Mobile Redirect with pretty URLs in .htaccess

I am trying to redirect my main site (www.mainsite.com) to my mobile site (m.mainsite.com) based on user agent in .htacess. I used the following code and it redirects to the m.mainsite.com properly.
RewriteCond %{HTTP_USER_AGENT} (Android|AU-MIC|AUDIOVOX|ALCATEL|Blackberry|Blazer|Googlebot-mobile|Handheld|iPhone|iPod|Klondike|LG-|LGE-|Nokia|NokiaN8|Opera\ Mini|PalmOS|PalmSource|Smartphone|Symbian|WebOS|Windows\ CE|Windows\ Mobile|Windows\ Phone|nokia|UP.Link|UP.Browser)
RewriteRule (.*) http://m.mainsite.com/$1
However, when taken to the mobile site I seem to be losing the rewritten URL. So what should be m.mainsite.com/page1 goes to something like m.mainsite.com/index.php?url=page1.
I tried rewriting the URL using .htaccess on the mobile site but could not figure out how to remove the part after index.php. Can anyone help me figure out how to remove "index.php?url=" from m.mainsite.com/index.php?url=page1?
Or would it be easier to figure out how to address this via htaccess in the non-mobile version during the redirect.
Full code looks like:
[code]
RewriteCond %{HTTP_HOST} ^mainsite.com
RewriteRule (.*) http://www.mainsite.com/$1 [R=301,L]
RewriteRule ^(.*)\_(\?.*)?$ $1$2 [R=301,L]
RewriteRule .* - [env=REWRITE_ON:1]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.(js|css|png|jpg|gif)$
RewriteRule ^(.*)$ index.php?url=$1 [L]
RewriteCond %{HTTP_USER_AGENT} (Android|AU-MIC|AUDIOVOX|ALCATEL|Blackberry|Blazer|Googlebot-mobile|Handheld|iPhone|iPod|Klondike|LG-|LGE-|Nokia|NokiaN8|Opera\ Mini|PalmOS|PalmSource|Smartphone|Symbian|WebOS|Windows\ CE|Windows\ Mobile|Windows\ Phone|nokia|UP.Link|UP.Browser)
RewriteRule (.*) http://m.mainsite.com/$1[code]
Thanks
Gary
Looks like you have other rules that's interferring. You need to put all of your redirect rules before any internal routing rules. The index.php?url=page1 looks like your routing rule.
Place the mobile redirect near the top of your htaccess file.

URL Rewrite multilanguage site

I have a multilanguage website made using wordpress running on apache 2.2. The url structure is www.domain.it for italian and www.domain.it/?lang=es for (for example) spanish.
My client owns also www.domain.es. My goal is to have users write www.domain.es and be redirected to www.domain.it/?lang=es
this is my htaccess:
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.es$
RewriteRule ^(.*)$ http://www.domain.it/$1/?lang=es [QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
the last four rows are for wordpress to provide index.php in some specific cases. The other two are mine to achive the goal. What I get now is a 302 page telling me that the document has moved (it says again to www.domain.es. If I add R=301 I get no more luck.
What am I doing wrong? Can anyone help me to stop banging my head around?
Do you want it to redirect? Or just handle the rewriting internally somehow?
You may need the L flag to tell it to stop trying to do anything else and just do that redirect:
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.es$
RewriteRule ^(.*)$ http://www.domain.it/$1/?lang=es [L,QSA,R=301]

.htaccess - Redirect subdomain to folder

This question has probably been asked for over a thousand times, but I've tried so many scripts, and googled so long while finding nothing, I thought, let's just ask.
I simply want m.daltonempire.nl to be redirected to daltonempire.nl/m/ without the user seeing the URL change.
So if m.daltonempire.nl/hello.php is requested, I want the user to keep seeing this URL, while the page given is actually daltonempire.nl/m/hello.php.
Note: I do not want www., so simply http://m.daltonempire.nl
Thanks in advance,
Isaiah v. Hunen
Add this to your .htaccess in your web root / directory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^m\.daltonempire\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*)$ m/$1 [L]
The %{REQUEST_FILENAME} conditions would let you access /exists.php and not rewrite it to /m/exists.php. Remove those two if you want to rewrite even if that may potentially override existing files and directories.
Try this example:
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule (.+)$ "http://example.com/%1" [L,P]
Any requests http://test.example.com will be mapped to http://example.com/test/...
Try googling dynamic subdomain with php and htaccess to get better search results.
I have set CNAME of my sub domain below:
blog.mydomain.com
to my wordpress that installed in folder /blog/ under root directory.
Formerly I need to use this url to call wordpress:
http://blog.mydomain.com/blog/
which is ugly. I have tried many code to redirect:
http://blog.mydomain.com/
to the folder so I can use it as my wordpress url.
Finally I got .htaccess setting that is work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1
I have also CNAME other subdomain: http://forum.mydomain.com to mybb installation in folder /forum/mybb/ so the .htaccess need to put [L] on each of RewriteRule code as below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^forum\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/forum/mybb/
RewriteRule (.*) /forum/mybb/$1 [L]
RewriteCond %{HTTP_HOST} ^blog\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1 [L]
In case you want to use the code please don't forget to set the site url and cookie path in the application config file follow to the setting to make the redirection work properly.

Categories