2013-01-25 03:36
采纳率: 100%
浏览 201

无法获取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 it should forward to the page

Similarly, if the user accessed the URL it should forward to

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>

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]

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.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试获取 .htaccess 文件以将所有网址转发到单个网址 带有url参数的页面,以便我可以通过这种方式处理页面检索。 我想要发生的是:用户输入 ,它应转发到页面。 php?url = / users / dan

同样,如果用户访问了URL 它应该转发到

这是我在中尝试过的代码 .htaccess 文件,但它只是向我抛出500错误:

 &lt; IfModule mod_rewrite.c&gt; 
RewriteEngine On 
RewriteCond%(REQUEST_FILENAME)!  -f 
RewriteRule(。*)$ index.php?url = $ 1&lt; QSA,L&gt; 
&lt; / IfModule&gt; 

我更新了 我的代码,这仍然是一个500错误 我改变了&lt; 和&gt; 到[和]我删除了RewriteCond中%之后的空格,但它仍然会抛出错误。

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

我' 对于 .htaccess ,新手,所以任何帮助都会非常感激,因为我不知道是什么导致服务器超时。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanbing6955 2013-01-25 03:39

    Couple of problems

    1. Rewrite flags go in square-brackets, eg

    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


    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]
    解决 无用
    打赏 举报

相关推荐 更多相似问题