doutan1875 2011-10-20 22:52
浏览 38

.htaccess - mod_rewrite适用于某些页面但不适用于其他页面

I am stuck into a weird problem.

I have a file at the location /public_html/academics/courses.php

I want .htaccess to mod_rewrite the URLs as below:

Original URL: http://niecdelhi.ac.in/academics/courses/

After mod_rewrite: http://niecdelhi.ac.in/index.php?inc=/academics/courses/

What I want, basically, is to mod_rewrite all URLs to index.php and pass the URL as a parameter named "inc". Then, in the index.php I include the file by doing include($_GET['inc']);

mod_rewrite is working for some pages on the website. and I am getting the URL in $inc. But, it is not working at all for other pages.

For example, consider the two files that exist on the server:

  1. http://niecdelhi.ac.in/academics/courses.php
  2. http://niecdelhi.ac.in/academics/library.php

mod_rewrite is working for the first, the file gets included in index.php But for the second I get the plain existing file. not the one included in index.php

I hope you understand the problem that I am facing. Please provide me with the solution.

.htaccess file

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !\..*$ [NC]
RewriteCond %{QUERY_STRING} (.*) [NC]
RewriteRule ^(.*)$ index.php?inc=$1&%1 [L]

Page working: http://niecdelhi.ac.in/academics/courses/

Page not working: http://niecdelhi.ac.in/academics/library/

*EDIT*

There is no other .htaccess anywhere. Although, I have found a clue about what is happening. The problem is happening only in Linux server. The code is working correctly in Windows server.I have a Linux server with PHP 5.2.16.

Also, regarding some pages working and some not. I have found that only those pages are working which have a folder with identical name in the same directory. For example, The academics directory is as below:

academics/
    |_ courses/
    |    |_ mba.php
    |    |_ mca.php
    |_ courses.php
    |_ library.php

Now, Since courses.php has a folder with identical name in same directory. It gets mod_rewrite fine. But library.php is not getting mod_rewrite.

Linux server is skipping the mod_rewrite for the files that actually exist. Why so ??

  • 写回答

1条回答 默认 最新

  • douhe8981 2011-10-20 23:32
    关注

    My only guess is that there is another .htaccess somewhere in your structure (most obviously inside /academics/ ) that is overriding the rule for "library".

    Could there be another mod_rewriting rule inside that folder that is kicking in for the word LIBRARY and probably messing up your rewriting.

    Note that it might also be a native apache issue. For example, in ubuntu, by default in version 10.10 (i think thats it) if you had a /javascript/ folder, it would be short circuited to /usr/lib/javascript or something like that...

    Check all possible instances of mod rewrite in httpd.conf, all dynamicaly loaded .conf files, your vhost file and finaly the path of your document root...

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?