0

我的.htaccess文件中有这样的声明:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    IndexIgnore */*

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d

    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

我的文件存储在: 中C:\xampp\htdocs\test505,com\,并且我有一个名为test505.com指向该目录的虚拟主机,以及一个在C:\Windows\System32\drivers\etc\hosts文件中定义的主机,也名为test505.com.

我什localhost至定义了一个指向 的虚拟主机C:\xampp\htdocs,它工作正常。

如果我运行:http://test505.com/并在 / 之后填写 URL,它将按预期工作,但如果我这样做:localhost/test505.com/,它将无法正常工作并且 URL 不会被覆盖......

我怎样才能让它在两个主机名上正常运行,不管路径名?

我不知道如何解决这个问题,所以任何帮助表示赞赏!


注意:我使用 PHP 和 Yii 框架,并启用了 URL 格式的 URL 路径。

4

1 回答 1

0
 # For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^localhost\/test505\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://test505.com:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^localhost\/test505\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://test505.com/$1 [L,R]

像这样的东西可以提供帮助。尝试阅读http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

于 2013-07-24T14:19:04.317 回答