【发布时间】:2019-03-25 02:44:37
【问题描述】:
我有一个非常复杂的 .htaccess 文件,其中包含许多 RewriteRules 到目前为止,除了我尝试重写一个不是 index.php 的文件时,所有这些都运行良好
我尝试添加 [L] 我使用 xampp 在本地运行它 index.php 和 deleteItem.php 都是有效文件。值得注意的是,我的规则不能再直接指向 PHP 文件了。
这是我的 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /smartsharing/community/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*?([^/]*)/members$ index.php?action=members&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/members/$ index.php?action=members&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/members/edit$ index.php?action=editMembers&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/members/edit/$ index.php?action=editMembers&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/items/edit$ index.php?action=editItems&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/items/edit/$ index.php?action=editItems&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/items/([^/]*)/purchasehistory$ index.php?action=purchaseHistory&id=$2 [L,QSA]
RewriteRule ^.*?([^/]*)/items/([^/]*)/purchasehistory/$ index.php?action=purchaseHistory&id=$2 [L,QSA]
RewriteRule ^.*?([^/]*)/items/([^/]*)/edit$ index.php?action=editItem&id=$2 [L,QSA]
RewriteRule ^.*?([^/]*)/items/([^/]*)/edit/$ index.php?action=editItem&id=$2 [L,QSA]
RewriteRule ^.*?([^/]*)/items/([^/]*)/remove$ deleteitem.php?id=$2 [L,QSA]
RewriteRule ^.*?([^/]*)/items/([^/]*)/remove/$ deleteitem.php?id=$2 [L,QSA]
RewriteRule ^.*?([^/]*)/edit$ index.php?action=edit&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/edit/$ index.php?action=edit&id=$1 [L,QSA]
RewriteRule ^.*?([^/]+)$ index.php?action=details&id=$1 [L,QSA]
RewriteRule ^.*?([^/]*)/$ index.php?action=details&id=$1 [L,QSA]
</IfModule>
我的网址类似于http://localhost/smartsharing/community/communityname/items/2/remove
我希望重写后的 URL 是 http://localhost/smartsharing/community/deleteItem.php?id=2 但它似乎去 http://localhost/smartsharing/community/index.php?action=details&id=2
当发布到http://localhost/smartsharing/community/doAction.php 时,它会重定向到http://localhost/smartsharing/community/index.php?action=details&id=doAction.php
【问题讨论】:
-
我个人讨厌将
.htaccess用于复杂的事情。我不太擅长。我将每个请求重定向到/handle_request.php(内部),并且我有一个路由器可以根据 URL 确定要做什么。并不是说您必须切换到那种做事方式。但这就是我所做的。.htaccess快把我逼疯了,哈哈
标签: apache .htaccess mod-rewrite