homepage Welcome to WebmasterWorld Guest from 54.196.168.78
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess rewrites not working
surrealillusions




msg:4514705
 3:13 pm on Nov 1, 2012 (gmt 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?

 

g1smd




msg:4514708
 3:22 pm on Nov 1, 2012 (gmt 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.
surrealillusions




msg:4514712
 3:54 pm on Nov 1, 2012 (gmt 0)

Ok, the Wordpress stuff was already in there.

How do I exclude internal requests? And why does the RewriteBase /index.php look incorrect?

lucy24




msg:4514828
 10:21 pm on Nov 1, 2012 (gmt 0)

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 ;)

surrealillusions




msg:4515890
 3:12 pm on Nov 5, 2012 (gmt 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.

vincevincevince




msg:4515891
 3:16 pm on Nov 5, 2012 (gmt 0)

I think (but am not certain) that Wordpress redirects index.php to the root

surrealillusions




msg:4515899
 3:34 pm on Nov 5, 2012 (gmt 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.

g1smd




msg:4515900
 3:35 pm on Nov 5, 2012 (gmt 0)

Looking at THE_REQUEST with a RewriteCond checks that it is an external request.

lucy24




msg:4515957
 5:31 pm on Nov 5, 2012 (gmt 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.

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.

vincevincevince




msg:4516343
 3:02 pm on Nov 6, 2012 (gmt 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');

surrealillusions




msg:4516369
 4:22 pm on Nov 6, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved