Forum Moderators: phranque
RewriteEngine on
#
## internally rewrite extensionless file requests to .html files ##
#
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI}!(\.[^./]+)$
# then add .html to get the actual filename
RewriteRule (.*) /$1.html [L]
I placed this in the httpd.conf file. Like I said when i go to http://www.example.com/test it resolves to http://www.example.com/test.html which is what I want but when I placed it into PROD it doesn't work. I am trying to do this for only one file in the entire site, which is really big. I am a newbie to this and I am noticing a lot of rewrites and ifmodules all over the file.
I know that there is a difference in the way that it should be written if it is in the conf file or in a .htaccess file, which I tried by the way and didn't work. Any way that you suggest would be greatly appreciated.
Thanx
Cesar
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !\.[^./]+$
# then add .html to get the actual filename
RewriteRule (.*) $1.html [L]
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !\.[^./]+$
# then add .html to get the actual filename
RewriteRule ^/(.*) /$1.html [L]
Jim
However, this is a minor adjustment, so the location decision usually revolves around two issues - Efficiency and maintainability. The code will be more efficient (executed less often) if located in the directory where it is to be applied, or 'closer' to the directory where it is to be applied. On the other hand, the code will be easier to maintain --and the possibilities for unexpected code interactions less likely to go unnoticed-- if the code is 'centralized' in the top-level .htaccess file.
The choice between putting the code in a server config file such as httpd.conf or conf.d versus putting it in .htaccess files also boils down to two primary issues - Efficiency and ease of testing. Code in .htaccess is interpreted for each HTTP request. That is, it is parsed as plain-text and converted to an executable equivalent for every HTTP request that involves the directory in which it resides. This is inefficient, but does allow .htaccess code to be changed at any time --even on-the-fly-- and take immediate effect, without requiring a server restart.
On the other hand, code located in the server config files such as httpd.conf or conf.d is compiled at server restart. That is, it is parsed as plain-text and converted into native CPU instructions once at server restart, and this code image is subsequently used while processing HTTP requests; the original text file is not used again until the server is restarted. So in contrast to code in .htaccess, the same code in a server config file executes *much* faster and more efficiently, but requires a server restart before any changes to that code will take effect.
As a result, many Webmasters opt to develop and test their code in a .htaccess context, and then 'port' that code over to the server config level after it has been tested and debugged.
Note that the majority of Webmasters don't have a choice; Since most of them are on shared name-based servers, they do not have access to the server config files, so .htaccess is the only choice. These Webmasters cannot make use of some of the powerful features available in httpd.conf, such as the ability to define RewriteMaps or to declare custom log file formats (just to name two).
Jim
in the docroot dir and the dir that has the file and still nothing.
Unfortunately I could not get this to work. I tried a work around that works, to a certain extent. My alternate solution is that I created another directory called 'library'. In it I placed the file that I wanted to get to which I called index.html. This works when I type out the address using the server name. As soon as I use the actual site name [site.com...] it doesn't work. One thing that I noticed in the httpd.conf file was that the virtual host was set up like this:
<VirtualHost www.site.com:80>
ServerName www.site.com
## Include security.conf
RewriteEngine On
RewriteLogLevel 1
RewriteLog logs/rewite.log
## Rewrite Setup for istore. Need to include url_fw_istore_http.conf
RewriteRule ^/(.*) [server.comp.com:8090...]
ProxyRequests Off
ProxyPreserveHost On
<IfModule mod_proxy.c>
ProxyPass / [server.comp.com:8090...]
ProxyPassReverse / [server.comp.com:8090...]
ProxyPass /OA_HTML/ [server.comp.com:8090...]
ProxyPassReverse /OA_HTML/ [server.comp.com:8090...]
ProxyPass /OA_HTML/dir/ [server.comp.com:8090...]
ProxyPassReverse /OA_HTML/dir/ [server.comp.com:8090...]
ProxyPass /oa_servlets/ [server.comp.com:8090...]
ProxyPassReverse /oa_servlets/ [server.comp.com:8090...]
ProxyPass /servlets/ [server.comp.com:8090...]
ProxyPassReverse /servlets/ [server.comp.com:8090...]
</IfModule>
</VirtualHost>
So when I try to hit server.comp.com:8090/OA_HTML/library it doesn't work. But when I try server.comp.com:8000/OA_HTML/library it resolves perfectly. Any ideas? This is the conf file on the proxy server.