0

我有一个 URL 重写设置来创建漂亮的 URL

RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]

当我使用/adminURL访问管理区域时,/admin/?rq=admin因为我有一个名为“admin”的根级目录而被重写。这可能很简单,但是我如何编辑(或添加)我的 .htaccess 规则,以便将 url 清晰地写为/admin/

更新:为了澄清,我想使用/index.php?rq=admin而不是通过调用 /admin/index.php来访问 /admin

这是我的 apache 虚拟主机配置:

<VirtualHost *:80>
        ServerAdmin alex
        ServerName hub
        ServerAlias hub
        DocumentRoot /var/www/hub/
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/hub>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
4

2 回答 2

2

只需将该admin文件夹添加到RewriteCond. 现在,您有例外,admin/assets因此您可以删除该assets部分并为整个admin文件夹保留例外,如下所示:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin|site\/assets|robots.txt|sitemap.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]
于 2012-11-21T10:52:15.467 回答
1

似乎添加DirectorySlash Off到我的 .htaccess 中就可以了。不确定这是否是正确的解决方法,但它解决了我的特定问题。我必须确保完全清除缓存以防止缓存重定向(感谢卡米尔)

在 Chrome 中:Chrome-> Tools -> Clear Browsing Data -> Empty the Cache

于 2012-11-21T15:46:39.423 回答