【发布时间】:2015-06-05 06:37:07
【问题描述】:
我的网站http://www.musicea.com.au 有动态网址。我使用 .htaccess 重写了静态 URL。当我复制重写的静态 URL 并直接粘贴到它们打开的浏览器中时。但他们不会自动重定向。我的代码如下所示。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page-([0-9]+)\$ content.php?pageid=$1 [L]
RewriteRule ^$ content.php?pageid=home
RewriteRule ^about$ content.php?pageid=1341369117 [L,NC]
RewriteRule ^music-lessons$ content.php?pageid=1344314997 [L,NC]
RewriteRule ^piano-lessons$ content.php? pageid=1347926925&getsubnavid=1344314997 [L,NC]
RewriteRule ^keyboard-lessons$ content.php?pageid=1347927089&getsubnavid=1344314997 [L,NC]
RewriteRule ^guitar-lessons$ content.php?pageid=1347927135&getsubnavid=1344314997 [L,NC]
RewriteRule ^violin-lessons$ content.php?pageid=1347927198&getsubnavid=1344314997 [L,NC]
RewriteRule ^content.php?pageid=home$ http://www.musicea.com.au/ [L,NC]
我认为 URL 已正确重写,但重定向存在问题。 请给我建议。
【问题讨论】:
-
哪些不起作用,您是如何在浏览器中输入它们的?我可以告诉你最后一个不会,因为 rewriterule 忽略了模式中的查询字符串。在您的第一条规则中,也不要逃避 $。
-
我重写的所有东西都是手动工作的。例如,当我手动输入musicea.com.au/music-lessons 时,URL 会打开。但它不会自动从动态重定向:musicea.com.au/content.php?pageid=1344314997。请忽略最后一个。我会删除它。
-
那是因为你没有规则告诉它这样做。您必须创建一个规则,以便如果他们输入旧 URL,它将重定向到新 URL。
-
谢谢。你能告诉我我该怎么做吗?这将是很大的帮助。
标签: .htaccess mod-rewrite url-rewriting url-redirection