dongye6377 2014-01-09 00:21
浏览 71
已采纳

使用htaccess路由index.php

I am running wamp on win7 just in case. I am trying to route all requests through a route.php to get clean URLs. Below is my htaccess

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI}  !(auth|folder2) [NC]
RewriteCond %{SCRIPT_FILENAME} !-f  
RewriteRule ^(.*) ./route.php?path=$1 [L]

As you can see the rule should apply to all files, and it did when I ran it on my old wamp installation. Now after copying the files to a new system, for some reason, the rule seems to work for all links except index.php. So if I try http://localhost/proj, I get no routing in the new system. Any ideas?

And before anyone asks, yes rewrite_module is on, and the htaccess is being read and executed cause it works for all other links like http://localhost/proj/users and also because if I try putting garbage values in the htaccess it throws a nice 'internal server error'.

  • 写回答

1条回答 默认 最新

  • dpvomqeu396484 2014-01-09 00:29
    关注

    I'm guessing you have an index.php in that folder, and this condition:

    RewriteCond %{SCRIPT_FILENAME} !-f  
    

    ...tells apache to perform the rewrite only if the file does not exist.

    I would suggest or renaming the file, as you'll need that condition to route static assets like images, scripts, etc.

    If there is no index.php (or index.htm[l]) in that folder, just define route.php as the default file in that directory. In your .htaccess:

    DirectoryIndex route.php index.php index.html index.htm
    

    (Be aware that this will also apply to any sub-directories as well)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?