homepage Welcome to WebmasterWorld Guest from 54.167.174.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
.htaccess RedirectMatch 301
LinusIT



 
Msg#: 4254280 posted 6:06 pm on Jan 17, 2011 (gmt 0)

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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4254280 posted 7:01 pm on Jan 17, 2011 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved