1

I have very similar problem like this one: Apache mod_rewrite - prefer files over directories with pretty URLs

However it is not same, and solutions mentioned in above link doesn't work for me.


My directory structure looks like this:

/pages/articles/january.php
/pages/articles.php
/pages/home.php
/articles/
/index.php

Now, I am including in index.php pages (depending on url).

For example, when user types address www.domain.com (or www.domain.com/home), index.php will include /pages/home.php

But if I enter this URL: www.domain.com/articles it will make link something like this: www.domain.com/articles/?page[]=articles (in other words index.php won't include /pages/articles.php file)

On the other hand, this works perfectly: www.domain.com/articles/january

This is my htaccess file:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9+]*)/([a-zA-Z0-9+]*)$ %{DOCUMENT_ROOT}/index.php?page[]=$1&page[]=$2 [QSA,L]
RewriteRule ^([a-zA-Z0-9+]*)$ %{DOCUMENT_ROOT}/index.php?page[]=$1 [QSA,L]

I use array for page because I can have subpages (and subpages work fine!).

EDIT: I have found this however it doesn't solves my problem :(


Can someone tell me why it does this and how to fix it?

Or, how can I give priority to files instead directories?

EDIT 2: I solved it by removing "/articles/" directory, however I am still interested how to make it work through htaccess file rules.

Community
  • 1
  • 1
DRAX
  • 30,559
  • 2
  • 26
  • 28
  • When you say, `" it will make link something like this: www.domain.com/articles/?page[]=articles"`, do you mean that URL actually shows up in the browser, meaning a redirect is being performed? Or are you just interpreting what's happening based on behavior? The rules you've shown don't redirect, so if you are getting a redirect it must be coming from somewhere else. Another thing to be aware of: since you have an actual articles directory, mod_dir may be adding a slash on the end of the URL, in which case your first rule would match instead of your second. – David Ravetti Jan 30 '13 at 22:44
  • Yes, it redirects. I have no other rules. However I solved it by removing that folder. And I have modified rule slightly (slashed you named). But I am still curious how can I give priority to files instead folders (I tried putting Options -MultiViews, but no success) – DRAX Jan 31 '13 at 00:07
  • Sorry, I realize now that I have different directory structure, post is updated. – DRAX Jan 31 '13 at 00:07
  • 1
    Well, you'd probably want to split into two sets of rules. Have an earlier rule that uses the `-d` flag in a RewriteCond to catch directories so that it could treat them differently as needed or, alternately, ignore directories in the first rule by negating the flag then catch them in the later rule. – David Ravetti Jan 31 '13 at 00:26
  • Thank you :) Please post it as answer, I would like to set it as accepted. – DRAX Jan 31 '13 at 01:02

1 Answers1

1

Per the comments above, your original issue was worked around by removing the articles directory, but you still wanted to be able to deal with directories in that sort of situation.

You'd probably want to split into two sets of rules. Have an earlier rule that uses the -d flag in a RewriteCond to catch directories so that it could treat them differently as needed. Alternately, ignore directories in the first rule by negating the flag (!-d) then catch them in the later rule.

David Ravetti
  • 2,030
  • 1
  • 17
  • 22
  • Thanks :) I just want to add: if someone needs to see how code should look like, please take a look at this link: http://stackoverflow.com/a/273704/1221512 – DRAX Jan 31 '13 at 01:21