Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- permanent 301 redirect - shtml to php without extension.


g1smd - 8:12 am on Apr 29, 2012 (gmt 0)


It's too late to redirect a request to a different URL once you have rewritten the request to fetch the content from a non-default location on the server hard drive.

The rules should be redirect first, rewrite second.

The redirect should include target domain name. Additionally, (.+) is too general a pattern. You need ([^.]+) here.

The rewrite with (.*) pattern captures all requests. The -f condition forces the server to check the hard drive to see if this request matches a real file. This takes forever. If it's not a file the request is then rewritten and the pointer now points at a .php filename. mod_rewrite then checks the htaccess file again, and the (.*) pattern again captures this request and the hard-drive is once again checked to see if this request matches a real file. This takes forever. The request does now match a real file and mod_rewrite exits. The content handler now takes over and checks to see if this file exists. It does, and the file is fetched and served.

The -f code is very very inefficient. The hard drive is checked several times per request. The (.*) pattern captures all requests. Since you know you want to rewrite only extensionless requests change the rule pattern to match only extensionless requests (something like ([^/.]+) or (([^/]+/)*[^/.]+) will do it) and delete the -f condition.

Add a non-www to www redirect after the shtml redirect and before the internal rewrite.


Thread source:: http://www.webmasterworld.com/apache/4447100.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com