繁体   English   中英

htaccess:重写规则不起作用

[英]htaccess: rewritten rule doesn't work

我想将“联系人”更改为index.php?controller=Front&action=$1&page=12 ,我得到了404:

在此服务器上找不到请求的URL / symfony / LocAtMe / web / contact”

这是我的htaccess中的代码:

AddType application/x-httpd-php .tpl .inc
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ index.php?controller=default&action=index [QSA]
    RewriteRule ^contact$ index.php?controller=Front&action=$1&page=12 [QSA, L]
    RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1 [QSA]
</IfModule>

任何帮助,不胜感激。

QSA,后的重写标志中不能有空格:

RewriteRule ^contact$ index.php?controller=Front&action=$1&page=12 [QSA,L]
# can't have a space here ----------------------------------------------^

尽管这不会导致404。您还应该仔细检查是否已加载mod_rewrite。 如果未加载,则删除<IfModule mod_rewrite.c></IfModule>行应导致500错误。

确保上面的代码放在DOCUMENT_ROOT/symfony/LocAtMe/web/.htaccess ,然后使用以下代码:

RewriteEngine on
RewriteBase /symfony/LocAtMe/web/

RewriteRule ^$ index.php?controller=default&action=index [QSA,L]
RewriteRule ^(contact)/?$ index.php?controller=Front&action=$1&page=12 [QSA,L]
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?page=$1 [QSA,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM