【发布时间】:2014-04-11 06:18:11
【问题描述】:
我正在尝试通过在灯系统上使用 htaccess 来了解 url 重写方法。
我是我的网站站长,我拥有系统的完全访问权限 (ubuntu 12.04)。
我成功配置了 htaccess 以删除 www 和 index.php,所以它似乎工作正常。 当我尝试重写本示例中的经典 URL 时出现问题(网络上有数千个这样的 URL):
RewriteEngine on
RewriteRule ^products/([A-Za-z0-9-]+)/?$ results.php?products=$1 [NC]
我想重写
mysite/results.php?products=string
到
mysite/string
所以我认为这是正确的例子。 无论如何,它不起作用。 我尝试了几个类似的例子,但我不明白为什么它根本不起作用。
我的 .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# Always remove www (with a hard redirect)
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
# Try
RewriteCond %{QUERY_STRING} ^page=(\d+)
RewriteRule ^products/([A-Za-z0-9-]+)/?$ results.php?products=$1 [R=301,QSA,L,NC]
</IfModule>
任何建议将不胜感激。
【问题讨论】:
-
RewriteRule ^(.*)$ /index.php/$1 [L]- 你的这条规则匹配服务器接收到的每个 URL,[L]意味着它应该在此之后停止处理任何规则。这可能就是您的重写规则不起作用的原因。
标签: php apache .htaccess mod-rewrite url-rewriting