dongpigui8898 2016-07-14 10:29
浏览 32
已采纳

如何在htaccess中将www重定向到没有www的内页

I was working on web based ifsc code search engine called Myifsccodes.com. I am the only person who developed it fully using Php and mysql. I made it redirect from WWW version to without WWW for home page in Bluehost Cpanel that uses htaccess 301 redirect. Its working fine for home page. But recently i found that, if i put www for inner pages they are not redirecting to the without WWW version, which is a huge duplicate problem for site's SEO.

I tried various fixes from Stackoverflow other similar questions, but nothing works accurately. This question is my last hope to fix it with experts here.

Here is my current .htaccess code

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.myifsccodes\.com$
RewriteRule ^/?$ "http\:\/\/myifsccodes\.com\/" [R=301,L]

# Use PHP54 Single php.ini as default
AddHandler application/x-httpd-php54s .php

# For security reasons, Option followsymlinks cannot be overridden.
Options +SymLinksIfOwnerMatch

RewriteCond %{REQUEST_FILENAME} !-f

# data compression
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/javascript

# Url format sample http://myifsccodes.com/example-bank

RewriteRule ^([a-zA-Z0-9_-]+)/$ /bankdetails2.php?banknamefromhtaccess=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ /bankdetails2.php?banknamefromhtaccess=$1

I want to achieve below redirection;

My preferred version of this page http://myifsccodes.com/canara-bank

And this URL http://www.myifsccodes.com/canara-bank should redirect to above URL.

Similarly, 2nd level sub folder URLs should also redirect to non-www version of their respective page.

Example: This URL http://www.myifsccodes.com/canara-bank/delhi should redirect to this one http://myifsccodes.com/canara-bank/delhi

Please help me fix this issue as soon as possible.

  • 写回答

1条回答 默认 最新

  • drmticpet66231422 2016-07-14 10:40
    关注

    Try the following

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    RewriteCond %{HTTP_HOST} ^www\.myifsccodes\.com$
    RewriteRule ^/?$ "http\:\/\/myifsccodes\.com\/" [R=301,L]
    

    Into

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度