Php 具有多个参数的htaccess不工作,?
我正在尝试使用htaccess文件重写URL,我在这方面没有任何经验,我所做的一切都是从这里和谷歌上搜索。我的链接中有查询参数。我将所有内容发送到index.php页面 我已经测试了所有的链接,然后试图重写它们,它们都在索引页面中工作。然后我创建了一个htaccess文件来重写链接,但是我得到的只是一个空白页面,没有任何变量被发送到索引页面。我在index.php页面中使用$\u GET来检索变量 下面是我试图重写的链接类型列表,以及我的实际htaccess文件的副本,mod rewrte也在apache中打开并正常运行。请帮助我更改我的htaccess文件,以便根据我下面显示的示例链接完全执行我想要的操作,好吗 目录重写是很好的,并相应地工作,这是链接不 此外,如果您注意到在链接#1和链接#2中,页面参数不会也不应该出现在这两个链接的重写的链接中,但仍然会向my index.php发送一个空字符串 范例--Php 具有多个参数的htaccess不工作,?,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正在尝试使用htaccess文件重写URL,我在这方面没有任何经验,我所做的一切都是从这里和谷歌上搜索。我的链接中有查询参数。我将所有内容发送到index.php页面 我已经测试了所有的链接,然后试图重写它们,它们都在索引页面中工作。然后我创建了一个htaccess文件来重写链接,但是我得到的只是一个空白页面,没有任何变量被发送到索引页面。我在index.php页面中使用$\u GET来检索变量 下面是我试图重写的链接类型列表,以及我的实际htaccess文件的副本,mod rewrte也在a
重写这些类型的链接
注意-“http://”是所有这些链接的前面,堆栈溢出不允许我添加它并发布
链接#1 localhost/notetag2/johnsmith/all/1 --重写为-- localhost/notetag2/index.php?page=&user=johnsmith&act=all§ion=1
链接#2 localhost/notetag2/johnsmith/all --重写为-- localhost/notetag2/index.php?page=&user=johnsmith&act=all
链接#3 localhost/notetag2/search/johnsmith --重写为-- localhost/notetag2/index.php?page=seach&search=johnsmith
链接#4 localhost/notetag2/pictures/1 --重写为-- localhost/notetag2/index.php?page=pictures&xx=1
重写目录 页数 --改写为-- 网
这是我实际的HTACCESS文件
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /notetag2/
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ notetag2/index.php?page=$1&user=$2&act=$3§ion=$4 [L,NC]
RewriteRule ^(.*)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ notetag2/index.php?page=$1&user=$2&act=$3 [L,NC]
RewriteRule ^(.*)/([a-zA-Z0-9_-]+)/?$ notetag2/index.php?page=$1&user=$2 [L,NC]
RewriteRule ^(.*)/$ notetag2/index.php?page=$1 [L,NC]
RewriteRule ^search/([a-zA-Z0-9_-]+)/?$ notetag2/index.php?page=search&q=$1 [L,NC]
RewriteRule ^pictures/([a-zA-Z0-9_-]+)/?$ notetag2/index.php?page=picturesh&xx=$1 [L,NC]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ $1.php [L,NC]
RewriteRule ^pages/(.*) web/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /notetag2/index.php [L,QSA]
</IfModule>
重新启动发动机
重写基本/注释标记2/
重写规则^index\.php$-[L]
重写规则^(.*)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$notetag2/index.php?页面=$1,用户=$2,法案=$3,章节=$4[L,NC]
重写规则^(.*)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$notetag2/index.php?页面=$1,用户=$2,动作=$3[L,NC]
重写规则^(.*)/([a-zA-Z0-9_-]+)/?$notetag2/index.php?页面=$1,用户=$2[L,NC]
重写规则^(.*)/$notetag2/index.php?页面=$1[L,NC]
重写规则^search/([a-zA-Z0-9_-]+)/?$notetag2/index.php?page=search&q=$1[L,NC]
重写规则^pictures/([a-zA-Z0-9_-]+)/?$notetag2/index.php?page=picturesh&xx=$1[L,NC]
重写规则^([a-zA-Z0-9_-]+)/?$$1.php[L,NC]
重写规则^pages/(*)web/$1[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。*/notetag2/index.php[L,QSA]
您需要修复几个正则表达式。由于htaccess文件位于notetag2目录中,因此不需要与前面的“notetag2”匹配
但首先,你的规则顺序不对。如果要匹配/search/something
,则不能有匹配任何内容的规则,否则它将匹配/search
。因此,这些规则需要放在首位:
RewriteRule ^search/([a-zA-Z0-9_-]+)/?$ index.php?page=search&q=$1 [L,NC]
RewriteRule ^pictures/([a-zA-Z0-9_-]+)/?$ index.php?page=picturesh&xx=$1 [L,NC]
在规则的目标中也不需要notetag2/
,因为这是隐含的,因为规则位于notetag2目录中
因此,在这两条规则之后,您需要从最大值到最小值进行其他每次重写:
localhost/notetag2/johnsmith/all/1
--改写为--
localhost/notetag2/index.php?page=tutorial&user=johnsmith&act=all§ion=1
你几乎已经做到了,只是在正则表达式前面有一些随机的(.*)/
,这将使它永远不会匹配你想要的。您希望这样做:
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ notetag2/index.php?page=tutorial&user=$1&act=$2§ion=$3 [L,NC]
那么下一个:
localhost/notetag2/johnsmith/all
--改写为--
localhost/notetag2/index.php?page=tutorial&user=johnsmith&act=all
“搜索”和“图片”应该按照上面的前两条规则处理
无论您在旧htaccess文件的底部有什么其他规则,它们都需要低于这些规则
因此,只剩下:
页数
--改写为--
网
由于这些不是以notetag2开头的,因此需要将这些规则放在不同的htaccess文件中,即文档根目录中的文件:
RewriteRule ^pages/(.*)$ /web/$1 [L]
为什么您的htaccess文件说“notetag2”,但您的问题希望将内容从/重写为“notetag”?他们应该是不同的吗?不,他们没有不同。他们是同一个人。我不使用复制粘贴。我把所有的东西都打出来了,只是在这里打错了。现在在我的帖子里已经改了。说notetag 2而不是notetag。你能帮我解答一下我的问题吗?你的htacces文件在哪里?我的htaccess文件在里面:localhost/notetag2或者更准确地说,它位于:C:\Users\MyComputer\Documents\xampp\htdocs\notetag2我正在我的计算机上使用xampp。htaccess的工作原理与我尝试创建了一行和两行htaccess文件并对它们进行了测试一样,他们所做的并不复杂。此外,mod rewrite也可以工作。不起作用的是我上面写的htaccess文件,因为它做了一些复杂的事情,我不知道如何在这个文件中正确执行它们!如果您注意到在链接#1和#2中,页面参数不会也不应该仅出现在这两个链接的重写链接中,但仍应将空白或空字符串发送到my index.php以表示该变量。前两个版本中没有$page=教程
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ notetag2/index.php?page=tutorial&user=$1&act=$2 [L,NC]
RewriteRule ^pages/(.*)$ /web/$1 [L]