[英].htaccess: URL Rewriting Pagination
这有效:
RewriteRule ^newest/?$ index.php?type=newest
这不起作用:
RewriteRule ^newest/(\d+)*/?$ ./index.php?type=newest&p=$1
我其余的重写:
IndexIgnore *
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
这适用于运行xampp的本地主机,但不适用于Web主机。 在与他们联系之前可能是什么问题?
需要检查的几件事...
您可能需要通过取消注释以下内容来在apache配置文件(httpd.conf)中启用htaccess:
;LoadModule rewrite_module modules/mod_rewrite.so
尝试确保服务器的httpd.conf中的目录条目不包含
AllowOverride None
因为这将防止.htaccess文件在单个目录中使用。 它应该看起来像这样(请注意AllowOverride All ):
<Directory /var/www/www.mysite.com>
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
同样在httpd.conf中,确保.htaccess实际上是apache期望用于访问文件的名称。 AccessFileName
指令可以指定此值。 例如:
<virtualhost>
ServerName www.mysite.com
DirectoryRoot /var/www/www.mysite.com
AccessFileName .customhtaccess
</virtualhost>
如果将AccessFileName
伪指令设置为其他值,则不会解析.htaccess文件。
您对这条规则的意图是什么
RewriteRule ^ newest /(\\ d +)* /?$ ./index.php?type=newest&p=$1
如果要匹配0个或多个数字,则应为
RewriteRule ^ newest /(\\ d)* /?$ index.php?type = newest&p = $ 1 [NC,L]
如果要匹配1个或多个数字,则应为
RewriteRule ^ newest /(\\ d)+ /?$ index.php?type = newest&p = $ 1 [NC,L]
您为什么不使用更有效的方法来执行此操作。 我建议使用这种模式:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
要将所有请求重定向到索引文件,则可以解析URL并执行所需的操作。 这不是针对您的问题的更正,而是避免工作的另一种方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.