首先,我正在尝试实现: 我正在测试基础http://example.com/subdir,这是所有子文件夹,index.php和.htaccess所在的位置。htaccess:相对路径不能正常工作
我有3个组的规则,如在.htaccess(额外的规则删除):
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
# Convert item/edit/xx -> index.php?p=edit&id=xx
# Convert item/remove/xx -> index.php?p=remove&id=xx
#RewriteCond %{REQUEST_URI} ^/item [NC]
#RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ [NC]
RewriteRule ^item/([a-z]+)/([0-9]+)$ index.php?p=$1&id=$2 [NC,L]
# Convert category/yyyy -> customer/pagination.php?category=yyyy
#RewriteCond %{QUERY_STRING} category=([a-zA-Z\s]+)$
RewriteRule ^customer/category/([a-zA-Z\s]+)$ customer/pagination.php?category=$1 [NC,L]
# Convert action/about -> index.php?p=about
# Convert action/terms -> index.php?p=terms
#RewriteCond %{QUERY_STRING} p=([a-z]+)$
RewriteRule ^action/([a-z]+)$ index.php?p=$1 [NC,L]
</IfModule>
我面对的是没有的RewriteCond工作(给路径未找到),所以它被注释掉的第一个问题目前为止。 RewriteRule在绝对路径下工作正常(例如RewriteRule^action /([az] +)$ http://example.com/subdir/index.php?p= $ 1 [NC,L]),但是这会导致浏览器显示真实的URL,因此我试图使它与相对路径。 我的问题是,在第一次重定向后,左侧链接的第一部分被添加到路径中,即http://example.com/subdir在点击动作/关于链接后变为http://example.com/subdir/action。 定义RewriteBase或将斜线前缀加到URL上只会让事情变得更糟。 我会感谢一位能够发现问题根源的鹰眼专家。
我真的不明白你的问题的第二部分。什么是导致错误的示例URL,您希望重定向到什么路径,以及它实际重定向到的路径是什么? – Anonymous
示例URL是:http://example.com/subdir/action/about。点击后,它会重定向到正确的关于页面,但下一个请求的路径将变为http://example.com/subdir/action/。因此,当您点击时,例如,操作/条款链接 - 生成的url = http://example.com/subdir/action/action/terms。请注意添加到路径中的额外“操作”文件夹(我需要重定向到http://example.com/subdir/index.php?p=terms)。所有链接都是相对的BTW,例如动作/约。谢谢。 – user2097141