1

我正在弄清楚如何清理我的 Silex 应用程序的 URL,该应用程序位于我的 apache 服务器的子目录中。这是实际路径:/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>

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

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...)

非常感谢大家!:)

4

1 回答 1

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等等

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

于 2014-06-24T11:59:26.353 回答