dtukyb8095 2017-04-03 22:03
浏览 108

htaccess RewriteRule导致404

We have a main site in a subdirectory where our main domain is pointed and a lot of sites in root subfolders. some of they are subdomains.

main site (laravel install):

public_html/mainsite/default/public/index.php

secondary sites

public_html/rec/index.php
public_html/raesta/index.php
public_html/acrup/index.php

htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(acrup) - [L]
    RewriteRule ^(raesta) - [L]
    RewriteRule ^(rec) - [L]
    RewriteRule ^(.*)$ mainsite/default/public/$1 [L]
</IfModule>

The main site domain is http://mainsite.edu.ar

The problem is when we try to access http://mainsite.edu.ar/recursos returns 404

It seems it's matching the /rec part of the url

we already tried:

RewriteRule ^(rec)/?$  - [L]

resulting in: http://mainsite.edu.ar/recursos works but http://mainsite.edu.ar/rec doesn't

http://mainsite.edu.ar/raesta and http://acrup.mainsite.edu.ar both works fine

  • 写回答

1条回答 默认 最新

  • matlabmann 2017-04-04 12:21
    关注

    Maybe try this instead:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^/acrup/ - [L]
        RewriteRule ^/raesta/ - [L]
        RewriteRule ^/rec/ - [L]
        RewriteRule ^(.*)$ mainsite/default/public/$1 [L]
    </IfModule>
    

    Your first try

    RewriteRule ^(rec) - [L]
    

    was hit by http://mainsite.edu.ar/recursos as well as http://mainsite.edu.ar/rec because both URIs (everything after the DNS-name mainsite.edu.ar) start with rec.

    Your second take

    RewriteRule ^(rec)/?$  - [L]
    

    didn't work, becuase you made the trailing slash optional with /? so still both URIs were hit.

    The difference with RewriteRule ^/rec/ - [L] is that it explicitly requires /rec/ --> a leading and trailing slash surrounding rec.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类