【问题标题】:Htaccess : making Fake folder to get accessible/Htaccess : 使 Fake 文件夹可以访问/
【发布时间】:2013-05-21 20:07:00
【问题描述】:

我已经创建了文件夹http://domain.com/sport/

我现在需要它做的是在我访问http://domain.com/sport/anything/anything/ 时显示http://domain.com/sport/index.php 的内容。

现在它的显示内容为http://livesports.pw/index.php

我尝试了下面的代码,但它不起作用。

RewriteEngine On
RewriteBase /
RewriteRule ^(.+)\/$ $1/ [R=301,L]

注意:文件夹 /sport/ 只是一个示例文件夹。它可以变化。即使创建了更多文件夹,它 即使是新的也必须工作。

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    用这个替换你的代码:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d [OR]
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^ - [L]
    
    RewriteRule ^([^/]+)/?$ /index.php [L]
    
    RewriteRule ^([^/]+)/(.+?)/?$ /$1/index.php [L]
    

    【讨论】:

    • 我希望 domain.com/anything 也指向 domain.com/index.php
    • 可以这样使用RewriteRule ^(.*)/(.*?)/?$ /$1/index.php [L]吗?
    猜你喜欢
    • 1970-01-01
    • 2014-04-25
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多