Forum Moderators: phranque
RewriteEngine on
RewriteBase /
RewriteRule ^image/(.*)/Pages/(.*)\.html$ image/$1/Pages/$2.php [R=301]
It seems to work, but whenever it redirects, it adds an additional slash to the final url:
[host.com...]
when I'd prefer it go to
[host.com...]
The only other post I've found referring to this was that the person wanted this type of behavior.
Welcome to WebmasterWorld [webmasterworld.com]!
Before we get too deep into this, here are two questions:
1) Does your code go into httpd.conf, or into an .htaccess file?
2) Do you want visitors and search engines to see the .php URL, or do you want them to see and use the .html URL?
Question 1 affects the form of the pattern on the left side of the RewritRule, and Question 2 affects the substitution on the right side, which is currently inconsistent with [R=301] flag.
Jim
1) I'm currently running the rewrite rule in a .htaccess file. The file also includes a number of standard Redirect 301 items.
2) Because I did physically rename all the files, I do want the browsers and search engines to actually go to the new .php pages instead of the old (and non-existant) .html files.
I'm not adverse to the idea of moving the rewrite rules to the httpd.conf, but put them in the .htaccess file since I didn't feel they were a permanent fixture.
I believe that the combination of your RewriteBase directive and the ill-formed substitution URL may be the cause of the double-slash problem -- I see no other reason for it. If a redirect is specified (as with (R=301]), then a canonical URL is required:
RewriteEngine on
RewriteRule ^image/([^/]+)/pages/([^.]+)\.html$ http://www.example.com/image/$1/pages/$2.php [R=301,L]
The [L] flag tells mod_rewrite that there is no need to process further rewriterules for the current HTTP request, and should be used unless you have a reason not to use it.
My point in question #2 is that there is no need to change URLs just because you changed to php technology. If you use an internal rewrite as opposed to an external redirect, then the old html URLs will still work, and there is no risk to your current search engine listings. An internal rewrite simply maps requested URLs to internal files in a way that is transparent to users and search engines alike.
In case you want to try it:
RewriteEngine on
RewriteRule ^image/([^/]+)/pages/([^.]+)\.html$ /image/$1/pages/$2.php [L]
Jim