Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mod rewrite 分页和修改重写_Mod Rewrite - Fatal编程技术网

Mod rewrite 分页和修改重写

Mod rewrite 分页和修改重写,mod-rewrite,Mod Rewrite,下面的modrewrite在我有了它的时候可以工作,这正是我想要的:“www.mysite.com/files/person/john.html” files.php?q=person Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/(.*) /$1.php?q=$2 [L] Rewr

下面的modrewrite在我有了它的时候可以工作,这正是我想要的:“www.mysite.com/files/person/john.html” files.php?q=person

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*) /$1.php?q=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
AddHandler application/x-httpd-php5 .html .htm .txt .php
我遇到的问题是,当我进行分页时,我有多个人像这样显示:“www.mysite.com/person/2”这变成person.php,但是没有person.php,modrewrite应该只查看以下情况:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
问题是,当我只有这个modrewrite时,“www.mysite.com/person/2”就起作用了:

Options +FollowSymLinks 
RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/(.*) /$1.php?q=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
AddHandler application/x-httpd-php5 .html .htm .txt .php

然而,在我取消注释它的那一刻,它就停止工作了?怎么办,有什么想法吗

您可以使用正则表达式进行此操作

DirectoryIndex index.php

<IfModule mod_rewrite.c>
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([a-zA-Z]+)(.html)?$ /$1.php?q=$2 [L]
RewriteRule ^(.*)/([0-9]+)$ /files.php?q=$1&p=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]

</IfModule>

你到底需要什么?你有没有person.php?你解释得很复杂,我没有person.php;基本上,当我进行分页时,我希望mod rewrite转到files.php。谢谢这个问题是当我只有这个www.mysite.com/person的时候我的网站就坏了。由于上面的方法不起作用,我给出了所有的代码,首先我给出的代码只是其中的一部分,试一下,告诉我是否有什么错误非常接近,当我有这样一个链接:www.mysite.com/person/2时,重写为:files.php?q=2,而应该是files.php?q=person;在我的php代码中,我实际上试图从“/person/2”中提取“2”。所以这个被称为:files.php?q=person,然后我从这里的链接中抓取最后2个:www.mysite.com/person/2用于分页。再次检查代码,使用此代码,您可以获得类似
$\u get['p']
$\u get['q']
的页面,将
person
确定将再次检查它。感谢您的帮助,您的帮助是最接近解决方案的。我会测试一下,然后告诉你。
()       : means group and match that
[a-zA-Z] : means only letters lower or upper
.html    : means match ".html"
?        : means 0 or more times
[0-9]    : means only numbers 0 to 9
+        : means at least 1 or more times