Forum Moderators: phranque
While people surfing directly to www.example.com ...the DirectoryIndex set will automatically serve up index.html which is what i have intended.
I have a simple IP based htaccess script working which redirects the users....
My domain is on a Cpanel & Apache 2.0...any idea on how to correct it...
it's on the main directory..
RewriteRule ^index\.html$ index\.shtml [L]
What, specifically, is the problem? You say the rule isn't working for your main directory, but then go on to say, "DirectoryIndex will automatically serve up index.html which is what i have intended." These statements appears to be contradictory.
If you wish to serve index.shtml in response to a request for "example.com/" then change the DirectoryIndex to specify index.shtml instead of (or prior to) index.html. However, the DirectoryIndex directive will be inherited by all subdirectories, so if you do this, then *all* subdirectories will use index.shtml as their index file (if it exists).
If you don't want that, then your rule can be changed to also apply to "example.com/" requests by making the URL-path optional in the pattern:
RewriteRule ^(index\.html)?$ index\.shtml [L]
Didn't know the ()?$ solved the problem.
Yes JD you have put it correctly I want to "apply to "example.com/" requests by making the URL-path optional in the pattern"
The problem was to the main folder.
my script goes as:
RewriteCond %{REMOTE_ADDR} ^92\.
RewriteRule ^(.*)\.html$ /$1\.shtml [L]
For the above script how do i set it to apply to "example.com/" requests by making the URL-path optional
Don't seem to be able to set:
RewriteRule ^((.*)\.html)?$ /$1\.shtml [L]
The server returns a 404 page not found when infact it's already there.
thanks
The easiest solution is a separate rule to handle that case, using "^$" as the pattern and /index.shtml as the substitution. Reproduce your REMOTE_ADDR RewriteCond if you also also want that condition on this new rule.
Jim
Any help here on this to now redirect multiple files from html to shtml ...as provided for index.html to index.shtml
thanks
1) You cannot use the "RewriteRule ^((.*)\.html)?$ /$1\.shtml [L]" modification, because as you found out -- and as I explained, it will result in a rewrite to example.com/.html if example.com/ is requested. Put that back to what I posted above by removing the outer parentheses and the trailing question mark.
2) Your new rule is perfectly-correct, but as I mentioned, it appears that your existing rule requires an IP address range starting with "92." to invoke that rule. If you have the same requirement for the "/" page, then reproduce that RewriteCond for this new rule as well; RewriteConds only apply to the single rule that follows them, so if you need the condition to apply to more than one rule, then you need to reproduce the RewriteCond for both rules.
Jim
As advised by Jim, i created to rules as [er below.
RewriteCond %{REMOTE_ADDR} ^92\.
RewriteRule ^(.*)\.html$ /$1\.shtml [L]
RewriteCond %{REMOTE_ADDR} ^92\.
RewriteRule ^(index\.html)?$ index\.shtml [L]
No techie guy, but just needed some quick fix..thanks all.
RewriteCond %{REMOTE_ADDR} ^92\.
RewriteRule ^(.+)\.html$ /$1.shtml [L]
#
RewriteCond %{REMOTE_ADDR} ^92\.
RewriteRule ^$ /index.shtml [L]
Jim
[edited by: jdMorgan at 1:53 pm (utc) on Feb. 13, 2009]