Reputation: 35
I want to redirect old url to new with additional parameter
How can I prevent creating many youtube parameter ?
OLD: http://example.com/lady-gaga-monster
NEW: http://example.com/lady-gaga-monster-youtube
Currently htaccess
RewriteEngine on
RewriteRule ^(.*)-youtube?$ index.php?search=$1&source=youtube [L]
I add this line
RewriteRule ^(.*)$ http://example.com//$1-youtube [R=301,L]
And the result on browser http://example.com/lady-gaga-monster-youtube-youtube-youtube-youtube-youtube
Upvotes: 0
Views: 51
Reputation: 42984
You created an endless loop. You need to add a RewriteCOnd so that the rule gets only applied if the requested URL does not end in "-youtube":
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# external rewrite
RewriteCond %{REQUEST_URI} !-youtube$
RewriteRule ^(.*)$ http://example.com/$1-youtube [R=301,L]
# internal rewrite
RewriteRule ^(.*)-youtube$ index.php?search=$1&source=youtube [L]
And a general hint: you should always prefer to place such rules inside the http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess
style files). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).
Upvotes: 1