douxie1692 2013-05-28 18:14
浏览 50

htaccess重写子域的条件/规则

I would like to rewrite all index files like /index in my subdomain as well as in my domain. Up to this point there was no need to use a subdomain. Now the problem is a rewrite rule from the htaccess file. This rewrites the URL as in the given code below:

RewriteRule ^index\.(htm|html|php) http://%{HTTP_HOST}/ [R=301,L]
RewriteRule ^(.*)/index\.(htm|html|php) http://%{HTTP_HOST}/$1/ [R=301,L]

Means that in the domain all index files will be rewritten. This works well but not in the subdomain. Now I thought I can simply add a condition for my subdomain like:

RewriteCond %{HTTP_HOST} !^subdomain\.example\.com$
RewriteCond %{HTTP_HOST} !^www\.

but this fortunately does not work.

To give further information here is what a URL looks like:

http://www.example.com/index
and the subdomain:
http://subdomain.example.com/index

With the code above the URL will be:

http://www.example.com/
and the subdomain:
http://subdomain.example.com/index

It would be great if someone could help me out.

Thanks alot.

UPDATE:

To give further information I need to explain how things work.

In the root dir there is the folder for the subdomain.

                                    --> /index.php
                      --> /folderA 
       --> /subdomain               
/root                 --> /folderB
                                    --> /index.php

The URL´s look like that:

http://www.example.com/subdomain/folderA/index

and

http://subdomain.example.com/folderA/index

I do use clean URL´s so that it is just index and not index.php etc. Default settings already hide index.php when calling a page. The problem will be when I will change the languages what means folderA and folderB. Therefor I read out the basename of the file and use header function to redirect to the right dir. The main problem is the subdomain. In the domain it works well. Just when I have a index page from a folder with the URL:

http://subdomain.example.com/folderA/(index will be hidden)

and will read out the basename (=>index) and will header to:

http://subdomain.example.com/folderB/(index will be hidden)

it will be caused a problem. The URL will be rewritten in a wrong way. Or another simple example:

Having a logo button on all pages in root/subdomain/folderA/

This button is a link with just: <a href="/index.php">...</a>. The page URL will be: subdomain.example.com/folderA/filexy when clicking that link the URL will be rewritten to www.example.com/subdomain/folderA/

  • 写回答

2条回答 默认 最新

  • dsjpqpdm620596 2013-05-28 18:24
    关注

    Try this:

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^subdomain\.example\.com$ [NC]
        RewriteRule ^/index\.(htm|html|php)$  http://%{HTTP_HOST}/$1 [NC,R=301,L]    
    </IfModule>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题