0

我正在尝试设置重写规则,以便将 localhost/test/{this} 之后的任何内容转发到 localhost/test/index.php?{here}

我可以访问服务器,当前配置如下所示:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    <Directory /var/www/test/>
            AllowOverride All
            RewriteEngine On
            RewriteBase /
            RewriteRule ^(.*)$ index.php?$1      
    </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

但是目前,在访问 localhost/test/something 时没有显示 /localhost/test/index.php?something 它显示 localhost/index.php 所以它重写到错误的地方..有什么想法吗?谢谢

4

2 回答 2

0

在 /var/www/test 中创建 .htaccess 文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
于 2013-01-29T17:09:40.933 回答
0

已解决.. 我发现每当我包含 AllowOverride All 时,它都会重定向到 /index.php,然后发现我在之前的测试中留下了一个 .htaccess 文件,这把事情搞砸了。删除,更新了我的规则,现在可以工作了。感谢帮助!

于 2013-01-29T18:18:25.137 回答