3

I have seen several other threads about this but for some reason in my specific case the solutions are not working.

Here is the .htaccess

DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1

The desired effect is that index.php will load what ever page is requested in the GET (/events-diary = index.php?page=events-diary) & that works fine.

However I have some REAL directories which need to be accessible for example /admin/

The above .htaccess works perfectly fine as desired on my home computer MAMP, it works perfectly fine on my Amazon Micro, it will not work on the deployment server ipage.com

When you enter /admin it will redirect to the root index. When you type /admin/index.php it works, but you have to specify the index.php

I cant figure out when it seems to be ignoring the !-d

UPDATE:

index.php contains the following PHP

if(!isset($_GET['page'])){
    header("Location: home");
    exit;
}
$line=page_content($_GET['page']);

note that this functions fine on the other 2 servers, i dont see why it would behave differently on the 3rd.

4
  • What happens when you enter: example.com/admin/ in the browser?
    – anubhava
    Sep 17, 2015 at 6:38
  • it redirects to example.com/home which is index.php?page=home
    – RiquezJP
    Sep 17, 2015 at 6:39
  • 1
    Try to use -MultiViews with uppercase V.
    – Croises
    Sep 17, 2015 at 6:58
  • @Croises LOL amazingly it worked! Write an answer ill accept you.
    – RiquezJP
    Sep 17, 2015 at 7:05

3 Answers 3

1

Use:

Options +FollowSymLinks -MultiViews -Indexes

With -MultiViews with uppercase V.
For Apache, in some cases upper/lower case are very important

2
  • Thanks for the answer & a really great tip for the future. I think we all copy & paste a standard .htaccess & modify it, but we copy & paste bad practice without knowing a golden tip like this :-)
    – RiquezJP
    Sep 17, 2015 at 7:20
  • 1
    You're welcome, glad it worked out. I must say that I do not find very natural the way Apache handles this.
    – Croises
    Sep 17, 2015 at 7:23
0

Here is a different set of rewrite rules that might work for you:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [NC,L]

Are you trying to route things to /admin/index.php? If so, you could create a copy of your .htaccess, upload it to the /admin directory and set the RewriteBase to /admin.

or, if you wanted to turn the rewrite engine off in your /admin directory, you could create an .htacess file that contains:

RewriteEngine off
0

Difficult to post these suggestions in comment so resorting to an answer.

Try this rule:

ErrorDocument 404 default
ErrorDocument 403 default
DirectorySlash On
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes

RewriteEngine on
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteCond %{DOCUMENT_ROOT}/$1/ !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.