Opencart default language doesn't work - browser

I have OpenCart multi language store with Arabic and English, I set the default language to be Arabic, it works well for all devices except on Samsung where it will show the browser's language as a default language. I would like a a way to force the default language for my store to be Arabic.
my Website URL is : Qadooa.com

I got the solution for second language packs for opencart.
bugissue:
not showing icons (like: myaccount, language, etc..)
not putting your default language really to default on live webshops!
solution:
.htaccess.TXT (save this document as .htaccess (no TXT! save with *all documents selected)
then add the following text after line 31 (install Notepad++ to see line numbers):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

Related

Subdomain in .htaccess file only works with index

I have a subdomain setup in my .htaccess, which only seems to work with the default index.html page. I'd LIKE it to work for ANY page in the folder corresponding to the subdomain. Edited for privacy, assume my domain is example.org. The pertinent parts of the file look like this...
#subdomain
RewriteCond %{HTTP_HOST} ^subname\.example\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.subname\.example\.org$
# (a few lines added by my hosting company deleted -- see below)
RewriteRule ^/?$ "http\:\/\/example\.org\/subname\/" [R=301,L]
So the result of the above is that if I have an index.html page in my 'public-html' (root?), http://example.org and a different index.html stored in a sub-folder (having the same name as the subdomain), I will get this expected result, which works...
browse to: http://example.org results in viewing http:// example.org/index.html
browse to: http://subname.example.org results in viewing http:// example.org/subname/index.html
Great so far. This is what I expected when I created the domain name. However, given a specific file myfile.html stored in the subname folder, I would expect this to work also, and it doesn't...
browse to: http://subname.example.org/myfile.html results in a 404 error.
This despite the fact that browsing to http://example.org/subname/myfile.html works fine. In that case myfile.html is displayed. So is there anything I can do to modify the subdomain code to get the result I'm looking for? Namely, browsing to http://subname.example.org/ANYFILE should work as well as browsing to http://example.org/subname/ANYFILE, regardless of what 'ANYFILE' is. This, after all, is one of the main reasons I set up the subdomain to begin with!
Note: I confess that I relied on my hosting company's cPanel utility to create the subdomain code, so I asked for their tech support for help first. Long story short they didn't. Maybe what I hoped for is not actually possible?
Also, the lines I deleted' from the code had to do with something called "well-known/acme-challenge", added by my hosting company at some point. Since removing them had no effect on the behavior I've described, I left it out to avoid clouding the issue.
RewriteRule ^/?$ "http\:\/\/example\.org\/subname\/" [R=301,L]
This only "redirects" the document root. To redirect all URLs you need to change the above to read something like:
RewriteRule (.*) http://example.org/subname/$1 [R=301,L]
The $1 backreference refers to the URL-path captured in the RewriteRule pattern, ie. (.*).
No need to backslash-escape the colons, slashes and dots in the substitution string (that's typical of cPanel).
Also, the lines I deleted' from the code had to do with something called "well-known/acme-challenge", added by my hosting company at some point.
Those lines will likely be required when the (Let's Encrypt?) SSL cert auto-renews. (Although the above redirects to "http" - are you not using HTTPS?)
UPDATE:
RewriteCond %{HTTP_HOST} ^subname\.example\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.subname\.example\.org$
Just as an aside, these two conditions could be reduced to a single condition if you wanted. For example, the above is equivalent to:
RewriteCond %{HTTP_HOST} ^(www\.)?subname\.example\.org$

How do i change the .htaccess on cPanel's Online File Manager (ByetHost)?

I'm using ByetHost as my website's FTP service, i configure everything (besides uploading the stuff) via ByetHost's Vista Panel, which has a Online File Manager where i presume i could edit the .htaccess.
However when i arrive at the File Manager, i can't seem to find the .htaccess file, and there is also a lack of a Settings button too.
Here is what the File Manager looks like: (the htdocs is where all my website's stuff is at)
I know ByetHost and/or whatever this unknown File Manager is not well known, but i'd like to ask anyways if there's anyone that could help me on how to configure my .htaccess. I would appreciate it.
I had this issue too, and couldn't find any settings or otherwise.
So what I simply did was:
Just created a new file and named it .htaccess!
And a quick test, I put in the following to allow access to my .html pages without actually typing the extension:
RewriteEngine on
RewriteRule ^(.+)\.html$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ /$1.html [NC,END]
And it worked successfully.

htaccess 301 redirect while replacing characters in URL - Helicon ASAPI ReWrite module

I have an old site that is being rebuilt. Instead of using a folders structure, it is using sub-domains. The segments are different, but the redirect itself is pretty simple. I can handle it like so:
RewriteRule ^segment/blog/view$ http://blogs.site.com/segment/article [R=301,NE,NC,L]
RewriteRule ^segment/blog$ http://blogs.site.com/segment [R=301,NE,NC,L]
So if I had www.site.com/segment/blog, it will now go to blogs.site.com/segment.
If I had www.site.com/segment/blog/view/catchy_name_goes_here, currently it redirects it to blogs.site.com/segment/article/catchy_name_goes_here and I NEED it to go here: blogs.site.com/segment/article/catchy-name-goes-here.
My issue comes from a decision to change the separator in the URI. The old articles were built with underscores '_' and the new articles are built with hyphens '-'.
How can I replace the underscores in the article titles with hyphens?
Try these rules:
RewriteRule ^/segment/blog$ http://blogs.site.com/segment [R,I,L]
# replace _ by - repeatedly
RewriteRule ^(/segment/blog/view)/([^_]*)_+(.*)$ /$1/$2-$3 [I,N,U]
# all _s gone, now do a redirect
RewriteRule ^/segment/blog/view/([^_]+)$ http://blogs.site.com/segment/article/$1 [R,I,L,U]
I ended up having to use the following. I don't know how many people this might effect due to the unique settings for this site in particular, but thought I would post the answer so it could help anyone that might need it.
The full settings on this are a server running IIS with Server 2k. The site consists of several static content pages, vb script, classic ASP, dot Net, and this is all intertwined with ExpressionEngine pages. It's a mess to say the least. To top it off, Helicon Tech's ASAPI Rewrite Module version 3 is running on the server for .htaccess usage. No sub-expressions, groupings, etc. were taking or being followed/processed. The index.php rule was getting bypassed as well.
This all said, I ended up with the following which parsed everything I needed.
RewriteRule ^index.php/segment/blog/view/([^_]*)_+(.*)$ http://www.site.com/index.php/segment/blog/view/$1-$2 [R,NC]
RewriteRule ^index.php/segment/blog/view/([^_]*)$ http://blogs.site.com/segment/article/$1 [R=301,I,L,U]
RewriteRule ^segment/blog$ http://blogs.site.com/segment [R=301,NE,NC,L]
RewriteRule ^/segment/blog$ http://blogs.site.com/segment [R,I,L]

Mobile browser detection with .htaccess fails with Opera Mini

I'm having trouble figuring this one out. I'm trying to direct mobile traffic to the mobile version of a website via HTACCESS User-Agent sniffing, like so:
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|ipad|iphone|ipod|iemobile|mini|mobi|palmos|webos|googlebot\-mobile) [NC]
RewriteCond %{HTTP_HOST} ^mobile\.mywebsite\.com$
RewriteRule ^([aA0-zZ9\-\/]*)/([^/]*)$ /index.php?page=$1&q=$2&q2=$3&setview=mobile [L,QSA]
The string mini|mobi is where the Opera Mini browser should be detected. However, this does NOT happen. I've also changed that string to opera m and other variations. Still no luck.
This rewrite condition appears to work with other mobile browsers, but not Opera, and I don't understand why. Even the second condition, which checks for an explicit pointer to the mobile. subdomain also fails to deliver the mobile content.
I'm not an HTACCESS guru, so my first guess is that my syntax is wrong. But why does this work on other mobile browsers and not Opera Mini?
Thanks for looking!
UPDATE: 2012-06-08
I actually resorted to a different method by using PHP to check headers. For some reason my HTACCESS file did not detect certain header information. Even though karlcow's answer would validate, I was having trouble getting the iPhone and third-party Android browsers to validate. It wasn't until a page was passed to the PHP interpreter that I was able to read the information. I guess I just don't understand how that works.
Anyway, I borrowed code from an Internet search that I placed into a library function:
function get_device_view() {
$view='desktop';
if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
$view='mobile';
if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) || ((isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']))))
$view='mobile';
$mobile_ua=strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents=array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda ','xda-');
if(in_array($mobile_ua,$mobile_agents))
$view='mobile';
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0)
$view='mobile';
if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0)
$view='desktop';
return $view;
}
This function is called as part of a strapper process for the website so that before anything is output, the $view is returned so that appropriate pages and stylesheets are loaded.
Additionally, I modified my HTACCESS file to contain the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_COOKIE} !((^|;\s*)DD_VIEW=([^;]+))
RewriteCond %{HTTP_HOST} mobile\.buffalosbigdeal\.com
RewriteRule ^([aA0-zZ9\-\/]*)/*([^/]*)$ /index.php?page=$1&q=$2&q2=$3&setview=mobile [L,QSA]
As you can see I'm only redirecting explicit calls for the mobile. subdomain, and those not containing a cookie which retains the $view set during the strapper process.
My original intent was to perform browser detection exclusively using HTACCESS; because of simplicity and under premise of mod_rewrite's power. But in my frustration, and to meet the deadline, I compromised by settling for a more chunky method that may require more maintenance in the future.
Lesson learned: Build responsive websites based on browser capabilities (ie: resolution, touch, and DOM level), and do not rely heavily on user-agent strings. Have we yet a solution like this?
Thanks for looking.
Note that the pattern of Opera Mini string is
Opera/9.80 (J2ME/MIDP; Opera Mini/$CLIENT_VERSION/$SERVER_VERSION; U; $LANGUAGE) Presto/$PRESTO_VERSION
Mini is with an uppercase M. Hmm but you put NC which is for nocase, so that's not it.
Just to be sure could you try
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|ipad|iphone|ipod|iemobile|mobi|palmos|webos|googlebot\-mobile) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Opera\ Mini
Should it be
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'operamini')>0)
or should it be
if (strpos(strtolower($_SERVER['ALL_HTTP']),'operamini')>0)
I get a debug error using ALL_HTTP, but the error goes away when I use HTTP_USER_AGENT
Here is the debug error, as follows:
Debug Notice: Undefined index: ALL_HTTP in header.php on line 29

htaccess redirection

Ok my project is to make an old static site into a dynamic one. There are about 40 pages in the old site.
The new format will be in 2 languages for now, with the possibility for more in the future.
There are 2 sets of urls actually:
the basic ones: /index.html, /about.html, /contact.html
the rest: /folder1/page1.html, /folder1/page2.html, /folder3/page3.html, etc
The client wants the 2nd language to have the same pattern as the default one:
the basic ones: /language/index.html, /language/about.html, /language/contact.html
the rest: /language/folder1/page1.html, /language/folder1/page2.html, /language/folder3/page3.html, etc
The basic pages i can rewrite with htaccess:
# default language
RewriteRule ^about.html$ about.php?language= [NC,L]
#other language
RewriteRule ^([^/]+)/about.html$ about.php?language=$1 [NC,L]
As for the rest of the pages i am stuck.
In my database i have saved the existing urls and their content.
For example, for the basic language:
/folder1/page1.html will be served by dynamicpage1.php?language=&url=/folder1/page1.html
/folder2/page2.html will be served by dynamicpage1.php?language=&url=/folder2/page2.html
/folder3/page3.html will be served by dynamicpage2.php?language=&url=/folder3/page3.html
And for the other language:
/([^/]+)/folder1/page1.html will be served by dynamicpage1.php?language=$1&url=/folder1/page1.html
/([^/]+)/folder2/page2.html will be served by dynamicpage1.php?language=$1&url=/folder2/page2.html
/([^/]+)/folder3/page3.html will be served by dynamicpage2.php?language=$1&url=/folder3/page3.html
How can i construct these rules?
If i try: RewriteRule ^([^/]+)/(.*)$ subservices.php?language=$1&url=$2, it fails
You better specify/list possible languages in URL Rewriting rule -- it will be MUCH MORE accurate then. This rule works fine:
RewriteRule ^((EN|FR)/)?(.*\.html)$ /subservices.php?language=$2&url=/$3 [NC,QSA,L]
or
RewriteRule ^((english|french)/)?(.*\.html)$ /subservices.php?language=$2&url=/$3 [NC,QSA,L]
Change EN|FR to whatever languages you do use.
/index.html will be rewritten to /subservices.php?language=&url=/index.html
/FR/index.html will be rewritten to /subservices.php?language=FR&url=/index.html
/folder1/page1.html will be rewritten to /subservices.php?language=&url=/folder1/page1.html
/FR/folder1/page1.html will be rewritten to /subservices.php?language=FR&url=/folder1/page1.html
/ZZ/folder1/page1.html will be rewritten to /subservices.php?language=&url=/ZZ/folder1/page1.html (ZZ is not recognized as acceptable language).

Resources