How can I rewrite my url, ONLY for the directory photos
?
http://www.abc.com/photos/index.php?page=2
to http://www.abc.com/photos/page/2
My .htaccess
# Turn mod_rewrite on
RewriteEngine on
RewriteBase /
...
RewriteRule ^photos/index.php?page=([0-9]*)$ /photos/page/$1 [R=301,L]
RewriteRule ^photos/page/([0-9]+) index.php?page=$1
RewriteEngine On
RewriteRule ^photos/page/([a-zA-Z0-9-/]+)$ photos/index.php?page=$1 [QSA]
RewriteRule ^photos/page/([a-zA-Z0-9-/]+)/$ photos/index.php?page=$1 [QSA]
You don't mention which strings are dynamic, so I am assuming for this answer that page
and 2
are variable.
You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteCond %{REQUEST_URI} ^/photos/([^/]+)/([^/]+)/? [NC]
RewriteRule .* photos/index.php?%1=%2 [L,QSA]
Maps internally
http://www.abc.com/photos/key/val
with or without trailing slash
To:
http://www.abc.com/photos/index.php?key=val
Strings key
and val
are assumed to be variable while photos
is assumed to be fixed.
For permanent and visible redirection, replace [L,QSA]
with [R=301,L,QSA]
.