Welcome to WebmasterWorld Guest from 54.146.248.111

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess RedirectMatch 301

     

LinusIT

6:06 pm on Jan 17, 2011 (gmt 0)

5+ Year Member



Hi

I've just switched one of my sites from .html to .php, so I can use require_once and other handy php features.

I tried using this code to redirect all .html to .php and ok it works but it breaks other sections of my site:

RedirectMatch 301 (.*)\.html$ [mysite.com$1.php<...]

The section is breaks is an ecommerce setup with RewriteBase > RewriteRules. These are in place for search engine friendly URLS.

RewriteRule ^(.*)-p-([0-9]+).html$ product_info.php?products_id=$2&%{QUERY_STRING}


So all the products in the store are becoming .php and as such do not work. I probably could change the .html$ to .php$ but I don't want to mess with that really.

Is there anyway to apply the RedirectMatch 301 to only a certain part of the site or tell it to ignore certain folders.

Thanks

g1smd

7:01 pm on Jan 17, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Even though you now use PHP inside your files, you do not have to use ".php" in your URLs.

Keep both the same filenames and URLs as before, and set the server configuration to parse .html files for their PHP content.

OR

Change the filenames to ".php" and use an internal rewrite such that when ".html" URLs are requested, the server looks for the correct .php file to serve the content.

OR

Only as a last resort, change your URLs to use ".php" and set up a redirect so that when ".html" URLs are requested, they are redirected to the new URL.


One overall rule to apply is that if "any" of your rules use RewriteRule then use RewriteRule for "all" of the rules. That is, do not use Redirect or RedirectMatch at all. The reason is that you can't guarantee the order the rules will be parsed, as they are parsed "per module" and not in the actual order they appear in your configuration or .htaccess file.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month