Search code examples
.htaccesshttp-redirectexpressionengine

htaccess hide extension doesn't allow ExpressionEngine logins


So pretty much said it but, using this in my .htaccess

    Options +FollowSymLinks -MultiViews

    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /

    ## removes index.php
    # Add/Hide index.php from everything except admin
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond $1 !admin$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?$1 [L]

    ## hide .php extension
    # To externally redirect foo.php to foo
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L,NC]

    ## To internally redirect /dir/foo to /dir/foo.php
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^ %{REQUEST_URI}.php [L]

Will allow me to use /admin as a url, but will not allow me to log in,

If I remove this line RewriteCond $1 !admin$ [NC] it prepends index.php onto /admin making it index.php/admin and I can't see the page


Solution

  • What are you trying to achieve? Just removing index.php? If so this .htaccess works:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    Then you'll have to access /admin.php of course, or you can put it in a directory named /admin if you wish.