Forum Moderators: phranque
redirect:
[somesite.com...]
to
[somesite.com...]
Here is what I have treed:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*home\.php?cat=255\ HTTP/
RewriteRule ^(.*)home\.php$ [somesite.com...]
[R=301,L]
Any thoughts on what I might be doing wrong are appreciated...
Todd
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*home\.php?cat=255\ HTTP/
RewriteRule ^(([^/]+/)*)home\.php$ http://www.example.com/[b]$1[/b]thenewstaticpage.ht[b]ml?[/b] [R=301,L]
The pattern (([^/]+/)*) means "Match zero or more instances of (one or more characters not equal to a slash, followed by a slash), and store all such instances in $1." By looking for a specific condition to end the match (a slash), the pattern-matching is more efficient.
Because no back-reference to the RewriteCond pattern match is used, the second set of parentheses is not needed in the RewriteCond pattern.
Jim
I however cannot get the code to redirect for me. Here is the existing htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com
RewriteCond %{REQUEST_URI} ^/?$ [OR]
RewriteCond %{SERVER_PORT}!443
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*home\.php\ HTTP/
RewriteRule ^(.*)home\.php$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*home\.php?cat=255\ HTTP/
RewriteRule ^(([^/]+/)*)home\.php$ http://www.example.com/$1thenewpage.html? [R=301,L]
Should there be a question mark at the end of the html page on the last line of code? Also, can you explain to me why the $1 variable would not be placed after the .html in the last line of code.
Any help to get this going is very appreciated!
Regards,
Todd
There should be a question mark at the end of each of those last three rules, unless you want to pass the original query string through to the new URL.
> Also, can you explain to me why the $1 variable would not be placed after the .html in the last line of code.
Because anything that matched into $1 would then be appended after the .html in the new (substitution) URL, and Apache would ignore it there. Since it appears that what is being matched into $1 is the subdirectory path, it would make little sense to put that after the filename.
You have not explained what you intend all of your code to do, or what it actually does, or how that differs from what you want it to do. Therefore, I can only guess.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim