RewriteRule 正在创建新的 URL,但不会从动态的 URL 中重定向它们
RewriteRule is creating new URLs but not redirecting them from the dynamic ones
我的网站 http://www.musicea.com.au 有动态 URL。我使用 .htaccess 来重写静态 URL。当我复制重写的静态 url 并直接粘贴到浏览器中时,它们会打开。但它们不会自动重定向。我的代码如下。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page-([0-9]+)$ content.php?pageid= [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 已正确重写,但重定向存在问题。
请建议我。
这是我在评论中的意思的一个例子。您只有一个规则可以在内部重写您的 PHP 文件,但是您没有一个规则可以直接重定向对 php 文件的使用。因此,我将向您展示如何执行此操作的示例。我做了一个规则,这样你就可以看到了。但是因为您所有的 URI 都没有任何映射到您的动态 URL,所以您必须为每个规则执行类似的规则。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page-([0-9]+)$ content.php?pageid= [L]
RewriteRule ^$ content.php?pageid=home
RewriteRule ^about$ content.php?pageid=1341369117 [L,NC]
#redirect direct request for content.php for music lesson
RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /content\.php\?pageid=1344314997
RewriteRule ^ /music-lessons? [R=301,L]
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]
如果有帮助请告诉我。
我的网站 http://www.musicea.com.au 有动态 URL。我使用 .htaccess 来重写静态 URL。当我复制重写的静态 url 并直接粘贴到浏览器中时,它们会打开。但它们不会自动重定向。我的代码如下。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page-([0-9]+)$ content.php?pageid= [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 已正确重写,但重定向存在问题。 请建议我。
这是我在评论中的意思的一个例子。您只有一个规则可以在内部重写您的 PHP 文件,但是您没有一个规则可以直接重定向对 php 文件的使用。因此,我将向您展示如何执行此操作的示例。我做了一个规则,这样你就可以看到了。但是因为您所有的 URI 都没有任何映射到您的动态 URL,所以您必须为每个规则执行类似的规则。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page-([0-9]+)$ content.php?pageid= [L]
RewriteRule ^$ content.php?pageid=home
RewriteRule ^about$ content.php?pageid=1341369117 [L,NC]
#redirect direct request for content.php for music lesson
RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /content\.php\?pageid=1344314997
RewriteRule ^ /music-lessons? [R=301,L]
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]
如果有帮助请告诉我。