【问题标题】:mod_rewrite parameters for Silex being in a subdirectorySilex 的 mod_rewrite 参数位于子目录中
【发布时间】:2014-06-24 09:21:44
【问题描述】:

我正在研究如何清理位于我的 apache 服务器子目录中的 Silex 应用程序的 URL。这是实际路径:/domains/mydomain.com/public_html/silex,带有以下子目录:

public_html/
    css/
    images/
    js/
    .htaccess
    index.php
src/
templates/
vendor/

所以,如果我转到:http://www.mydomain.com/silex/public_html/,我会发现我的 Silex 应用程序运行正常,但在 URL 中您可以看到 public_html/ 目录。我想以某种方式隐藏它,因为我的所有页面(例如 about/contacts/ 等)将始终在它们前面包含该子目录。

如何避免?

这是我的.htaccess

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>

基本上,我只是希望我的网址变成这样:

http://www.mydomain.com/silex/about
http://www.mydomain.com/silex/contacts
http://www.mydomain.com/silex/admin
(etc...)

代替:

http://www.mydomain.com/silex/public_html/about
http://www.mydomain.com/silex/public_html/contacts
http://www.mydomain.com/silex/public_html/admin
(etc...)

非常感谢大家! :)

【问题讨论】:

    标签: apache .htaccess mod-rewrite silex public-html


    【解决方案1】:

    这里有几个选项(你必须把它们都放在第一个 public_html 的 .htaccess 中):

    1. 制作一个包罗万象的 RewriteRule 并使用 index.php 显示不同的内容 RewriteRule ^silex\/(.*)$ silex/public_html/index.php?screen=$1 [NC] - 有了这个,您可以使用 $_GET['screen'] 捕获 index.php 中的变量并相应地加载您希望的任何内容。
    2. 或者您可以制定特定规则以重定向到特定页面RewriteRule ^silex\/about$ silex/public_html/about.php | RewriteRule ^silex\/contacts$ silex/public_html/contacts.html

    如果您还有其他问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-19
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多