.htaccess - mod_rewrite 适用于某些页面,但不适用于其他页面
我陷入了一个奇怪的问题。
我在 /public_html/academics/courses.php 位置有一个文件,
我希望 .htaccess mod_rewrite 如下所示的 URL:
原始 URL:http://niecdelhi.ac.in/academics /courses/
mod_rewrite 之后: http://niecdelhi.ac.in/index.php?inc=/academics/courses/
我想要的,基本上,是将所有 URL mod_rewrite 到 index.php 并将 URL 作为名为“inc”的参数传递。然后,在 index.php 中,我通过执行 include($_GET['inc']); 包含该文件。
mod_rewrite 适用于网站上的某些页面。我得到了 $inc 中的 URL。但是,它对于其他页面根本不起作用。
例如,考虑服务器上存在的两个文件:
- http://niecdelhi.ac.in/academics/courses.php
- http://niecdelhi.ac.in/academics/ library.php
mod_rewrite 正在第一个工作,该文件被包含在 index.php 中 但第二次我得到了普通的现有文件。不是index.php中包含的那个
我希望你理解我面临的问题。请向我提供解决方案。
.htaccess 文件
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\..*$ [NC]
RewriteCond %{QUERY_STRING} (.*) [NC]
RewriteRule ^(.*)$ index.php?inc=$1&%1 [L]
页面工作:http://niecdelhi.ac.in/academics /courses/
页面无法正常工作:http://niecdelhi.ac.in/academics/library/
*编辑*
任何地方都没有其他 .htaccess。尽管如此,我已经找到了有关正在发生的事情的线索。该问题仅发生在 Linux 服务器中。该代码在 Windows 服务器中正常工作。我有一个使用 PHP 5.2.16 的 Linux 服务器。
另外,关于一些页面工作和一些不工作。我发现只有那些在同一目录中具有相同名称的文件夹的页面才能工作。例如,academics 目录如下:
academics/
|_ courses/
| |_ mba.php
| |_ mca.php
|_ courses.php
|_ library.php
现在,由于courses.php 在同一目录中有一个具有相同名称的文件夹。 mod_rewrite 很好。但library.php 没有得到mod_rewrite。
Linux 服务器正在跳过实际存在的文件的 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:
- http://niecdelhi.ac.in/academics/courses.php
- 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 ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我唯一的猜测是,您的结构中的某个地方(最明显的是 /academics/ 内)还有另一个 .htaccess 覆盖了“库”的规则。
该文件夹内是否存在另一个 mod_rewriting 规则,该规则会针对“LIBRARY”一词启动,并且可能会扰乱您的重写。
请注意,这也可能是本机 apache 问题。例如,在 ubuntu 中,默认情况下在版本 10.10 中(我认为就是这样),如果您有一个 /javascript/ 文件夹,它将被短路到 /usr/lib/javascript 或类似的东西...
检查所有可能的实例mod 重写 httpd.conf、所有动态加载的 .conf 文件、您的虚拟主机文件以及最后的文档根路径...
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...