【发布时间】:2017-06-27 20:25:26
【问题描述】:
我有一个这样的文件夹结构:
- index.php
- css/style.css
- images/image.png
- .htaccess
在我的 htaccess 中,我想添加一些规则以创建一个如下所示的 URL:home/5/6 转到页面:index.php?var1=5&var2=6
home/5 到 index.php?var1=5 按照我的方式工作:
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^home/(.*)$ index.php?var1=$1
RewriteCond %{REQUEST_URI} \.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^home/(.*)$ $1 [NC,L]
但是对于 2 个(或更多)变量,将其添加到我的 htaccess 时,css 和图像不再加载:
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^home/(.*)/(.*)$ index.php?var1=$1&var2=$2
RewriteCond %{REQUEST_URI} \.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^home/(.*)/(.*)$ $2 [NC,L]
在图像和 css 标签中我只使用相对路径。
【问题讨论】:
-
@starkeen 看起来是的,但是使用基本 href=/ 所有文件路径将从根目录开始,而我的工作目录可能位于未知子文件夹/位置