2011-08-16 134 views
0

的想法:我希望把它任何东西的域名后到来和结束以.html由index.php文件作为GET变量处理问题与阿帕奇(与WAMP)的mod_rewrite

例子:www.test.ro/1/2/3.html实际上应该是www.test.ro/index.php?var=1/2/3.html

www.test.ro被设置为虚拟主机进行开发,并且AllowOverride具有值All。

.htaccess文件似乎被处理,但不是所有的时间。如果我编写一个不可识别的规则,如'BizzareRule',则服务器工作时不会返回代码500错误。 如果我在<IfModule mod_rewrite.c></IfModule>之间放置了正确的规则,即使我有其他使用相同条件并完美工作的虚拟主机,也会得到500错误。

这里是我的虚拟主机的内容:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName www.test.ro 
    ServerAlias test.ro 

    DocumentRoot D:/Projects/grabsite/test.ro 
    Options Indexes FollowSymLinks MultiViews 

    DirectoryIndex index.php index.html 

    LogLevel warn 
    ErrorLog D:/Projects/grabsite/test.ro/error.log 
    CustomLog D:/Projects/grabsite/test.ro/access.log combined 

    <Directory "D:/Projects/grabsite/test.ro"> 
     Options -Indexes FollowSymLinks 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 

和测试内容的.htaccess:

RewriteEngine On 
RewriteRule ^/?([^/]*)\.html$ /index.php?seo=$1 [L] 

回答

1

看来你在无限循环进入。首先尝试简化规则: RewriteRule ^(.*)\.html$ /index.php?seo=$1 [L]

或者只是 RewriteRule ^index.html$ /index.php?seo=$1 [L]

其次,最好有-f的RewriteCond和的RewriteCond为了不如果要求现有的文件/文件夹执行规则-d。在某些情况下,这可以防止规则中的无限循环

0

问题在于正则表达式模式。你说:“.htaccess文件似乎被处理,但不是所有的时间”

如果您检查模式^/?([^/]*)\.html$你会看到,这会为文件在根文件夹的工作ONLY(例如/index.html)。

解决方案:变化图案^(.+)\.html$和所有将被罚款 - 现在将匹配以html的(例如/index.html以及/hello/pink-kitten.html等)结束ANY URL。