【问题标题】:Mod Rewrite to LocalhostMod重写到本地主机
【发布时间】:2015-09-08 03:58:22
【问题描述】:

我有一个 laravel 应用程序,我希望公用文件夹可以通过 apache mod_rewrite 访问。如果我希望我的 URL http://localhost/dev/admin 访问 http://localhost/dev/public/admin,我的 RewriteRule 应该是什么?

【问题讨论】:

  • 拥有可公开访问的/dev 目录会使/public 目录毫无意义,除非/dev 也被重写。我会尽快在您的本地主机上创建一个子域:dev.localhost/public/admin 然后将以下行添加到您的主机文件中以获取虚假域:127.0.0.0 dev.localhost 最后配置 apache 以添加虚拟主机:<VirtualHost *:80>ServerName dev.localhostDocumentRoot "C:/public_html/dev"@ 987654331@

标签: .htaccess mod-rewrite url-rewriting


【解决方案1】:

我相信您正在寻找这样的东西:

/dev/.htaccess

    RewriteEngine on

    #Because we're inside of a subdirectory
    RewriteBase /dev/

    #Handle the case of localhost/dev
    RewriteRule  ^$ public/    [L]

    #Handle the case of localhost/dev/...
    RewriteRule  ((?s).*) public/$1 [L]

    #The (?s) part is a Perl-style inline regex modifier meaning "single line"
    #so the dot will match unlikely new line characters.
    #I borrowed the idea from here:
    #https://docs.phalconphp.com/en/latest/reference/tutorial.html#beautiful-urls

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 2017-11-24
    • 1970-01-01
    • 2012-03-29
    • 2018-06-03
    • 2011-03-09
    相关资源
    最近更新 更多