Reputation: 37
I used to have a photo gallery that dynamically generated 1 page per photo, assigning each page's url a unique query string, such as:
https://www.example.com/photos/index.php?start=1 and https://www.example.com/photos/index.php?start=2
Since I don't have a ton of photos in my gallery, I've turned each page into static urls (which might help their seo rankings). Those same pages now have static urls such as:
https://www.example.com/photos/winterstorm2007.php and https://www.example.com/photos/new-chickens.php
Here is what I tried in the htaccess file inside my photos directory -- which just throws a 404 error:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^index\.php?start=1 [NC]
RewriteRule (.*) /photos/winterstorm2007.php [R=301,L]
RewriteCond %{QUERY_STRING} ^index\.php?start=2 [NC]
RewriteRule (.*) /photos/pastured-chickens.php [R=301,L]
Upvotes: 0
Views: 319
Reputation: 785186
QUERY_STRING
variable only contains query part after ?
in URL.
You may use THE_REQUEST
to match REQUEST_URI and query:
RewriteCond %{THE_REQUEST} /index\.php\?start=1\s [NC]
RewriteRule ^ /photos/winterstorm2007.php? [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\?start=2\s [NC]
RewriteRule ^ /photos/pastured-chickens.php? [R=301,L]
Also note trailing ?
in target URI to strip off previous query strings.
Upvotes: 1