dongyan1899 2013-01-25 03:36 采纳率: 100%
浏览 227
已采纳

无法获取mod_rewrite IfModule在.htaccess中工作

I'm trying to get my .htaccess file to forward all URLs to a single page with url parameters so that I can handle the page retrievals that way. What I want to happen is this: say the user types in http://mysite.com/users/dan it should forward to the page http://mysite.com/index.php?url=/users/dan.

Similarly, if the user accessed the URL http://mysite.com/random-link it should forward to http://mysite.com/index.php?url=random-link

Here is the code I tried in my .htaccess file, but it just keeps throwing a 500 error at me:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond % (REQUEST_FILENAME) !-f
RewriteRule (.*)$ index.php?url=$1 <QSA,L>
</IfModule>

I UPDATED MY CODE TO THIS AND IT STILL THROWS A 500 ERROR I changed the < and > to [ and ] and I removed the space after the % in the RewriteCond, but it still throws an error.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ index.php?url=$1 [QSA,L]
</IfModule>

I'm a novice when it comes to .htaccess, so any help would be greatly appreciated, because I don't know what's causing the server to timeout.

  • 写回答

1条回答 默认 最新

  • duanbing6955 2013-01-25 03:39
    关注

    Couple of problems

    1. Rewrite flags go in square-brackets, eg

      [QSA,L]
      
    2. Your RewriteCondition syntax looks incorrect. Try

      RewriteCond %{REQUEST_FILENAME} !-f
      
    3. Just to be on the safe side, anchor your expression to the start of the string

      RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
      

    Lastly, RewriteEngine and subsequent modifiers requires the FileInfo override. Make sure your server config or virtual host <Directory> section for your document root has

    AllowOverride FileInfo
    

    Update

    Here's a typical rewrite scheme from an MVC project. This will ignore real files, directories and symlinks

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?