dongluobei9359 2015-04-08 18:40
浏览 47
已采纳

htaccess将带有查询字符串的域重定向到带有排除的子域

We have moved our site to a subdomain while on the main domain we have a new site with new url's. What we are trying to do is having the old url's redirect to the subdomain while the excluding the new url's.

here's examples of the old url's:

http://www.domain.co.il/index.php?dir=app_admin&page=ip_stat&op=list&pos=0

should be redirected to:

http://sub.domain.co.il/index.php?dir=app_admin&page=ip_stat&op=list&pos=0

While the new site url's (do not contain php) and the homepage should not be effected.

This is what our htaccess looks like:

It does redirect the url's to the sub, but does not exclude the new pages and redirect them to the subdomain home (sub.domain.com)

RewriteEngine on    
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$  http://www.%{HTTP_HOST}/$1 [R=301,L]   

RewriteCond %{REQUEST_URI} !contact(|$)
RewriteCond %{REQUEST_URI} !about(|$)
RewriteCond %{REQUEST_URI}  index\.php
RewriteRule ^(.*)$ http://sub.domain.com [R=301,L]

Hopefully someone can help us get this right, we get many 404 in our gwt now :/

Thanks for any help !

  • 写回答

3条回答 默认 最新

  • dsm1998 2015-04-08 19:14
    关注

    Fix some regex and reorder your rules:

    RewriteEngine on    
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} !/(contact|about) [NC]
    RewriteCond %{THE_REQUEST} !\.(jpe?g|gif|bmp|png|tiff|css|js) [NC]
    RewriteRule ^(.+)$ http://sub.domain.com/$1 [R=301,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    

    Also test this in a new browser to avoid old browser cache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)