Forum Moderators: phranque

Message Too Old, No Replies

hidden file extension rewrite rule not working after change to new web

         

sailOn

6:19 pm on Sep 23, 2010 (gmt 0)

10+ Year Member



I've been using the following RewriteRules on a prior web host to be able to use URLs without file extensions, e.g.:
www.site.com/contact loads www.site.com/contact.php

.htaccess as follows:

ErrorDocument 404 /errPage.php
Options +FollowSymlinks

RewriteEngine on
RewriteBase /

# If the requested extensionless URL does not resolve to an existing directory, but does resolve to
# an existing .php file when ".php" is added, internally rewrite to add ".php" to the filepath
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
#
# If the requested extensionless URL does not resolve to an existing directory, and does resolve to
# an existing .html file when ".html" is added, internally rewrite to add ".html" to the filepath
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.html [L]

# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# secure php.ini file
<Files php.ini>
order allow,deny
deny from all
</Files>



I tested to see if the Rewrite engine is on & it is as this rule:
RewriteRule (.*) [selectAsite.com...]
does send my site e.g. to amazon's site when I add its URL to that rule then add the rule to the .htaccess file

Perhaps this may be useful info in troubleshooting -- my ErrorDoc line at top also is not being found, so errors are loading the web host's error page, not my site's error page

my site structure is /home/mysite and more specifically

Home
-
-
--www
-
-
--index.html
--direction.html
--blog
-
-
--index.php

I think RewriteBase / is still correct

I located this info in web host support documents, but I don't know if this is contributing to the problem or has nothing to do with my
rewrite rules not working
Article title: No trailing slash, URL without final /

Content of article: "Is there anyway to fix the problem where pages load incorrectly if you forget the trailing slash?
Yes! The setting called 'canonicalnames' must be off." (wouldn't fix the ErrorDocument line problem, either)

I can't help but think that some difference in server configuration is behind this, but admit I don't know how to troubleshoot this any further

This apache server uses CGI/FastCGI and SuPHP -- my prior web host with which this .htaccess and its rewrite rules did work properly, also used CGI/FastCGI

New host: apache vs 2.2.16
phpinfo states vs 5.2.14 but hyperlink on control panel states 5.2.4
phpinfo() does not output the loaded apache mod data and the support only states includes mod_rewrite and mod_security

Any thoughts about troubleshooting or a fix would be really appreciated

jdMorgan

12:50 pm on Sep 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most likely either your code is not located in the same directory as /errPage.php, or the DocumentRoot setting on this server is incorrect. It may in fact be what I call "incorrect" because the host deliberately set it that way in order to make their job easier (in some way, I won't guess). If this cannot be corrected, then a new host is needed, as you will be miserable constantly trying to work-around this anomaly in all of your rewrite code and scripts.

Jim