重写规则在WordPress中不起作用

时间:2013-11-25 作者:soul

我正在尝试使用重写API添加新的重写规则:

 add_rewrite_rule(\'product/([A-Z0-9]{10})\', \'index.php/product/?asin=$1\', \'bottom\');
 add_rewrite_rule(\'product/(([A-Za-z0-9_])*)\', \'index.php/product/?product=$1\', \'bottom\');
 add_rewrite_rule(\'compare/((([A-Z0-9]{10}),?)*)\', \'index.php/compare/?asin=$1\', \'bottom\');
 add_rewrite_rule(\'categories/(([A-Za-z0-9]|\\-|\\_)*)\', \'index.php/categories/?subcategory=$1\', \'bottom\');
更新永久链接后,它会将以下行添加到.htaccess 文件:

RewriteRule ^product/([A-Z0-9]{10}) /index.php/product/?asin=$1 [QSA,L]
RewriteRule ^product/(([A-Za-z0-9_])*) /index.php/product/?product=$1 [QSA,L]
RewriteRule ^compare/((([A-Z0-9]{10}),?)*) /index.php/compare/?asin=$1 [QSA,L]
RewriteRule ^categories/(([A-Za-z0-9]|\\-|\\_)*) /index.php/categories/?subcategory=$1 [QSA,L]
导致以下情况.htaccess 文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteRule ^product/([A-Z0-9]{10}) /index.php/product/?asin=$1 [QSA,L]
RewriteRule ^product/(([A-Za-z0-9_])*) /index.php/product/?product=$1 [QSA,L]
RewriteRule ^compare/((([A-Z0-9]{10}),?)*) /index.php/compare/?asin=$1 [QSA,L]
RewriteRule ^categories/(([A-Za-z0-9]|\\-|\\_)*) /index.php/categories/?subcategory=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
但当我尝试访问以下URL时:

http://example.com/product/ABCDE324AB
这似乎不起作用。我总是得到一个找不到的页面。有什么想法吗?

1 个回复
SO网友:Manish

我从上面了解到的是你有。htaccess文件和写入同一文件的正确代码,但仍然存在404问题。让我告诉你为什么。您的服务器不允许。htaccess文件以读取或覆盖权限。那么你怎么能给这个许可呢?打开Apache httpd。AllowOverride的conf文件serch现在您可以看到它多次出现。在同一文件中检查以下注释:

# AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None
只需更换AllowOverride None 通过AllowOverride All

现在重新启动APACHE 它应该会起作用

结束

相关推荐