Jump to content

Recommended Posts

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 by requinix
please use [code] tags when posting code-ish stuff
Link to comment
https://forums.phpfreaks.com/topic/302094-redirecting-problems/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.