Cld Posted September 7, 2016 Share Posted September 7, 2016 (edited) Hello i have a little problem with my htacess i think. Redirecting is working fine until. I share my web through facebook share button on mobile device. And when i click the link on desktop i still get redirected to mobile version. That means if i add /m at the end of my url ex: www.aaa.com/m it redirects me to mobile version. Can someone help me with this prob. Here is both of my htacces files: First one root htacces: # Disable directory listing from this point Options -Indexes # Prevent viewing of htaccess file <Files ~ "^\.ht"> order allow,deny deny from all satisfy all </Files> <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Redirect from www to non-www RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] # Disable rewrite for valid directory/files RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #map all request urls to a specific controller method RewriteRule ^(.*)$ index.php?/{controller}/{method}/$1 [L] # deny access to evil robots site rippers offline browsers and other nasty scum #RewriteCond %{HTTP_USER_AGENT} ^Anarchie #RewriteCond %{HTTP_USER_AGENT} ^ASPSeek #RewriteCond %{HTTP_USER_AGENT} ^attach #RewriteCond %{HTTP_USER_AGENT} ^autoemailspider #RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider #RewriteCond %{HTTP_USER_AGENT} ^Xenu #RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster #RewriteCond %{HTTP_USER_AGENT} ^Zeus #RewriteRule ^.* - [F,L] </IfModule> <FilesMatch "\.(css|js|jpeg|jpg|png|gif|html|php)$"> # Cache files for 1 WEEK #Header set Cache-Control "max-age=604800, proxy-revalidate" # Remove ETags Header unset ETag FileETag None </FilesMatch> # Expires Headers <IfModule mod_expires.c> # Enable expirations #ExpiresActive On # Default directive #ExpiresDefault "access plus 1 week" # My favicon #ExpiresByType image/x-icon "access plus 1 month" # Images #ExpiresByType image/gif "access plus 1 week" #ExpiresByType image/png "access plus 1 week" #ExpiresByType image/jpg "access plus 1 week" #ExpiresByType image/jpeg "access plus 1 week" # CSS #ExpiresByType text/css "access 1 week" # Javascript #ExpiresByType application/javascript "access plus 1 week" # Add a far future Expires header for fonts #ExpiresByType application/vnd.ms-fontobject "access plus 1 year" #ExpiresByType application/x-font-ttf "access plus 1 year" #ExpiresByType application/x-font-opentype "access plus 1 year" #ExpiresByType application/x-font-woff "access plus 1 year" #ExpiresByType image/svg+xml "access plus 1 year" </IfModule> # protect against DOS attacks by limiting file upload size - 10mb LimitRequestBody 10240000 And here is /m # Disable directory listing from this point Options -Indexes # Prevent viewing of htaccess file <Files ~ "^\.ht"> order allow,deny deny from all satisfy all </Files> <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /m/ # Redirect from www to non-www RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] # Disable rewrite for valid directory/files RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #map all request urls to a specific controller method RewriteRule ^(.*)$ index.php?/{controller}/{method}/$1 [L] # deny access to evil robots site rippers offline browsers and other nasty scum #RewriteCond %{HTTP_USER_AGENT} ^Anarchie #RewriteCond %{HTTP_USER_AGENT} ^ASPSeek #RewriteCond %{HTTP_USER_AGENT} ^attach #RewriteCond %{HTTP_USER_AGENT} ^autoemailspider #RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider #RewriteCond %{HTTP_USER_AGENT} ^Xenu #RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster #RewriteCond %{HTTP_USER_AGENT} ^Zeus #RewriteRule ^.* - [F,L] </IfModule> <FilesMatch "\.(css|js|jpeg|jpg|png|gif|html|php)$"> # Cache files for 1 WEEK #Header set Cache-Control "max-age=604800, proxy-revalidate" # Remove ETags Header unset ETag FileETag None </FilesMatch> # Expires Headers <IfModule mod_expires.c> # Enable expirations #ExpiresActive On # Default directive #ExpiresDefault "access plus 1 week" # My favicon #ExpiresByType image/x-icon "access plus 1 month" # Images #ExpiresByType image/gif "access plus 1 week" #ExpiresByType image/png "access plus 1 week" #ExpiresByType image/jpg "access plus 1 week" #ExpiresByType image/jpeg "access plus 1 week" # CSS #ExpiresByType text/css "access 1 week" # Javascript #ExpiresByType application/javascript "access plus 1 week" # Add a far future Expires header for fonts #ExpiresByType application/vnd.ms-fontobject "access plus 1 year" #ExpiresByType application/x-font-ttf "access plus 1 year" #ExpiresByType application/x-font-opentype "access plus 1 year" #ExpiresByType application/x-font-woff "access plus 1 year" #ExpiresByType image/svg+xml "access plus 1 year" </IfModule> # protect against DOS attacks by limiting file upload size - 10mb LimitRequestBody 10240000 Could anyone tell what code and in which of these files should i write ? Edited September 7, 2016 by requinix please use [code] tags when posting code-ish stuff Quote Link to comment https://forums.phpfreaks.com/topic/302094-redirecting-problems/ Share on other sites More sharing options...
requinix Posted September 7, 2016 Share Posted September 7, 2016 There is nothing in the root .htaccess that redirects to mobile, so either you're clicking a link to /m/something or your PHP code is doing the redirect. Quote Link to comment https://forums.phpfreaks.com/topic/302094-redirecting-problems/#findComment-1537132 Share on other sites More sharing options...
Cld Posted September 7, 2016 Author Share Posted September 7, 2016 Yes i am pressing a link /m/ so what would be the best way to still redirect it to dekstop version? Any solution here? Quote Link to comment https://forums.phpfreaks.com/topic/302094-redirecting-problems/#findComment-1537133 Share on other sites More sharing options...
requinix Posted September 7, 2016 Share Posted September 7, 2016 Current best practice, one I happen to quite dislike, is to use responsive design for your website: make it work on both desktop, tablet, and mobile devices by using CSS to affect what people see based on their device. For example, on a desktop (which has a large screen) most or all of the page appears normally, but on a phone (which has a small screen) some parts are hidden or otherwise altered so they appear differently. That results in one website running one set of PHP scripts with no URL rewriting necessary. Besides that there are two tactics: 1. Using a bit of Javascript on the client to detect the device and automatically redirect to the other version of the website if the user landed on the wrong one and has not explicitly opted to view the other one (typically involving setting and checking for a cookie). 2. Do user-agent detection on the PHP side to perform a similar redirect. #1 is the better of the two. There are other concerns too: - Search engines will penalize you for showing duplicate content at two different URLs. You need to use canonical URLs to indicate on the mobile site that the desktop site is the original source. - If you use any sort of redirect then you should pick one as the "normal" site and always link to that. It's not so much a technical thing as it is ensuring that you treat your website as two different views of the same content, rather than as two different websites. Mobile users landing on the desktop site will be redirected so there's no problem there. Quote Link to comment https://forums.phpfreaks.com/topic/302094-redirecting-problems/#findComment-1537134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.