Reputation: 79
My website http://www.musicea.com.au has dynamic URLs. I have used .htaccess to rewrite the static URLs. When I copy the rewritten static urls and paste directly in the browser they open. But they are not redirecting automatically. My code is as given below.
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]
I think the URLs are rewritten properly but there's problem in redirecting. Please suggest me.
Upvotes: 1
Views: 54
Reputation: 24448
Here is an example of what I meant in the comments. You only have a rule to internally rewrite to your PHP file, but you don't have a rule to redirect the use of the php file directly. So I'll show you an example of how to do that. I did one rule so that you can see. But because all your URI's don't have any mapping to your dynamic URL you will have to do a similar rule for each one of you rules.
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]
#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]
Let me know if this helped.
Upvotes: 2