Welcome to WebmasterWorld Guest from 54.146.194.42

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess rewrites not working

     
3:13 pm on Nov 1, 2012 (gmt 0)

Preferred Member

5+ Year Member

joined:Dec 10, 2007
posts: 507
votes: 0


I have this site where there are 2 home pages. One is a landing page, and the other is the wordpress home page.

Wordpress is at index.php
Landing page is at index.htm

The idea is that when people visit the site on the home url (example.com) then they get the landing page. However, the wordpress site should still be use-able and visit-able at index.php

This is the .htaccess file.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /index.php
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

DirectoryIndex index.htm


In theory, as far as I know, that should do what I'm after. But it doesn't. Whenever I visit index.php, it reverts to the home url, example.com and I get the landing page.

I cant ahold of the person who knows where the site is hosted, so therefore I cant contact the hosting company.

Any ideas?
3:22 pm on Nov 1, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Two guesses.

1. You need to exclude external requests for "/" from being rewritten so that the DirectoryIndex directive can then action the request. Mod_rewrite gets to it first and DirectoryIndex never gets a chance.

2. You need to exclude internal subrequests for index.htm from being rewritten. At present your ruleset only stops requests for index.php from being rewritten (this prevents an infinite loop). If requests (internal or external) for index.htm are rewritten, you'll never be able to access the index.htm file content.

--

You do not need the
<ifModule>
containers.

RewriteBase /index.php
- looks incorrect too.
3:54 pm on Nov 1, 2012 (gmt 0)

Preferred Member

5+ Year Member

joined:Dec 10, 2007
posts: 507
votes: 0


Ok, the Wordpress stuff was already in there.

How do I exclude internal requests? And why does the RewriteBase /index.php look incorrect?
10:21 pm on Nov 1, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12702
votes: 244


RewriteBase /index.php - looks incorrect too.

It is, but fortunately it has no effect. After very close poring over the documentation, it turns out that the RewriteBase is stuck onto the front of a Rewrite (capitalized) target when-and-only-when the target does not begin with protocol-plus-domain and does not have a leading slash. In other words, never ;)
3:12 pm on Nov 5, 2012 (gmt 0)

Preferred Member

5+ Year Member

joined:Dec 10, 2007
posts: 507
votes: 0


I'm still no nearer an answer for the problem.

How do I exclude internal requests? I can't find much meaningful documentation online about them.
3:16 pm on Nov 5, 2012 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


I think (but am not certain) that Wordpress redirects index.php to the root
3:34 pm on Nov 5, 2012 (gmt 0)

Preferred Member

5+ Year Member

joined:Dec 10, 2007
posts: 507
votes: 0


But I need the Wordpress site to function as it is, but, both index.htm and index.php need to function separately, with the index.htm taking preference for the root URL.
3:35 pm on Nov 5, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Looking at THE_REQUEST with a RewriteCond checks that it is an external request.
5:31 pm on Nov 5, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12702
votes: 244


But I need the Wordpress site to function as it is, but, both index.htm and index.php need to function separately, with the index.htm taking preference for the root URL.

Do you have a DirectoryIndex directive of your own? Generally on shared hosting you don't need one, because the server's config file has a generic version, and a normal directory won't have more than one index file. But here it is probably safer to have an explicit

DirectoryIndex index.htm index.php

OR

DirectoryIndex index.htm
DirectoryIndex index.php

Both versions work exactly the same. I think the one-line version is more intuitive. (And takes up fewer bytes ;))

The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory by specifying a / at the end of the directory name.... Several URLs may be given, in which case the server will return the first one that it finds.


Note carefully that Apache will stop at the first listed name that it finds; later names don't override earlier ones. So start with the form you want users to get if they simply request www.example.com.

If you want to look it up for yourself, note also that Apache's example shows it inside a <Directory> envelope. Do not use this envelope in htaccess. Ever. It isn't just unnecessary; it's an error.
3:02 pm on Nov 6, 2012 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


The problem is actually wordpress - this call, in a PHP file placed within a plugin, will solve the problem:

remove_filter('template_redirect', 'redirect_canonical');
4:22 pm on Nov 6, 2012 (gmt 0)

Preferred Member

5+ Year Member

joined:Dec 10, 2007
posts: 507
votes: 0


Thanks for all the replies.

Figured out it was actually Wordpress causing the issue. The remove_filter line above works fine when placed into the functions.php file. Along with the DirectoryIndex rule in .htaccess, has produced the effect I was after.