.htaccess htaccess重写添加了;index.php“;当我在地址中添加一个尾随斜杠时
我已经按照以下规则重写了htaccess:.htaccess htaccess重写添加了;index.php“;当我在地址中添加一个尾随斜杠时,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我已经按照以下规则重写了htaccess: RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)/([a-zA-Z0-9\-_]*)$ /content.php?a=$1&b=$2&c=$3 RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)$ /content.php?a=$1&b=$2 RewriteRule ^([a-zA-Z0-9\-]*)$ /index.php?a=$1 当我进入“mydomain.com/n
RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)/([a-zA-Z0-9\-_]*)$ /content.php?a=$1&b=$2&c=$3
RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)$ /content.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9\-]*)$ /index.php?a=$1
当我进入“mydomain.com/nameofpage”时,它的效果非常好
但当我添加一个尾随斜杠“mydomain.com/nameofpage/”时,浏览器会在末尾添加“index.php”,404的是我
想法
谢谢
编辑。
算出了
看起来我在前两次重写中使用*胜过了我的最终规则。。。长话短说,下面是正确工作的代码(在三个位置将*更改为+):
我想出来了——看起来我在前两次重写中使用*胜过了我的最终规则。。。长话短说,下面是正确工作的代码(在三个位置将*更改为+):
RewriteRule^([a-zA-Z0-9\-]*)/([0-9]+)/([a-zA-Z0-9\-+)$/content.php?a=$1&b=$2&c=$3
重写规则^([a-zA-Z0-9\-]*)/([0-9]+)$/content.php?a=$1&b=$2
重写规则^([a-zA-Z0-9\-]*)$/index.php?a=$1
只需在$
之前添加/?
就可以了。我刚刚尝试了,没有改变,但我没有足够的声誉来发布我自己的答案。。。这是:我想出来了。。。看起来我在前两次重写中使用*胜过了我的最终规则。。。长话短说,下面是正确运行的代码(在三个位置更改为+)RewriteRule^([a-zA-Z0-9\-]*)/([0-9]+)/([a-zA-Z0-9\-+)$/content.php?a=$1&b=$2&c=$3 RewriteRule^([a-zA-Z0-9\-])/([0-9]+)$/content.php?a=$1&b=$2 RewriteRule^[a-zA-Z0-9\-])/php]/$1编辑后的代码,添加您的解决方案+谢谢你自己解决它。欢迎这么说。是的,以后的重写可以胜过以前的重写,或者与以前的重写交互。您可以使用标志[L]
使该重写成为链中的最后一次重写。
RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]+)/([a-zA-Z0-9\-_]+)$ /content.php?a=$1&b=$2&c=$3
RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]+)$ /content.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9\-]*)$ /index.php?a=$1