繁体   English   中英

如何获取mod-rewrite以访问正确的目录?

[英]How do I get mod-rewrite to access the proper directory?

我正在尝试使用mod-rewrite消除诸如{root} /index.php?action=about&page=faq之类的网址。 我希望{root} / about / faq重定向到php url。 我的.htaccess文件看起来像

DirectoryIndex index.php
RewriteEngine On
RewriteRule ^(index|about|calendar|news|contact)$ index.php?action=$1 [L]
RewriteRule ^(index|about)/(.+)$ index.php?action=$1&page=$2 [L]

当重定向到index.php?action = $ 1时,这可以正常工作。 但是,使用第二个规则时,它不能完全起作用。 html内容看起来不错,但是样式表和图像丢失了。 该页面似乎认为它在子目录中。 因此,{root} / about / faq在about / images文件夹中查找图像,而不是在根目录下找到的images文件夹中查找图像。 PHP脚本说,工作目录仍然是根目录。 如何使页面认为它们位于根目录中? 谢谢!

    RewriteRule ^(index|about|calendar|news|contact)/(.*)/$ /index.php?action=$1&page=$2

会导致/ about / faq /重写为index.php?action = about&page = faq

/ calendar / month /将导致index.php?action = calendar&page = month

另外,除非您想重写图像文件,否则我将添加:

    RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png)$ [NC]

这将阻止图像请求被重写。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM