skip to Main Content

On a CentOS 6 running apache 2.4 and DirectAdmin, I have a wordpress website. Beside the wordpress standard architecture, I want to have some semi-static pages which are located in a sub-directory.

Filesystem is as: /home/user/public_html/sub/static1.php

Desired URL is as: https://domain/sub/static1

currently I have no problem opening the pages with .php extension. But I want to remove it. I have tried adding some rewrite rule in .htaccess but I have failed since the request gets redirected to homepage.

I have tried to find some solution online, including this website but nothing could help me. I assume DirectAdmin is involved in this issue.

Any help would be appreciated

2

Answers


  1. In your /home/user/public_html/sub/.htaccess file, use this code:

    Options -MultiViews
    RewriteEngine on
    
    # remove php
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{REQUEST_URI} !/index.php$
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
    RewriteRule ^ %1 [R=301,L]
    
    # rewrite with php php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/sub/$1.php -f
    RewriteRule ^(.+?)/?$ $1.php [L]
    
    Login or Signup to reply.
  2. You can use Apache mod_rewrite

    Just add this code to your root directory .htaccess

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule !.*.php$ %{REQUEST_FILENAME}.php [QSA,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search