【问题标题】:How to rewrite the url for Slim on a Subdomain如何在子域上重写 Slim 的 url
【发布时间】:2015-01-04 20:56:51
【问题描述】:

我在子域上使用 Slim 路由器时遇到问题。 路由器本身工作,我可以调用它,它不会导致任何错误,但 Slim 只是读取“/”路由。


文件夹

www
--- .htacccess
--- index.php
--- 其他东西
--- 子域
--- --- .htaccess
--- --- index.php
--- --- 其他东西


在 www/.htaccess 中:

重写引擎开启
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^..subdomain.example.de.
重写规则 ^ index.php


在子域/.htaccess 中:

重写引擎开启
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]


在子域/index.php 中:

需要“供应商/自动加载”
$app = new Slim\Slim();

$app->get('/', function () {
回声'什么都没有';
});

$app->get('/foo', function() {
回声'酒吧';
});

$app->run();


所以,当我打开 www.subdomain.example.com/foo 时,我得到“什么都没有”。 我认为问题是重写,但我不知道如何解决它。

感谢您的帮助。
乔希

【问题讨论】:

    标签: php .htaccess mod-rewrite url-rewriting slim


    【解决方案1】:

    我在subdomain/.htaccess 中通过以下方式解决了这个问题:

    RewriteEngine On <br>
    RewriteBase /dev-project/
    
    RewriteCond %{REQUEST_FILENAME} !-f<br>
    RewriteRule ^(.*)$ /index.php [QSA]
    

    【讨论】:

    • 什么是开发项目?子域中的目录?
    猜你喜欢
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 2014-11-14
    • 2012-09-17
    • 2013-06-22
    • 2014-05-15
    相关资源
    最近更新 更多