skip to Main Content

First off – sorry for asking this question again. It seems to be answered a million times – but I still can’t get my .htaccess to work.

The problem:
In public_html we have a working website and an .htaccess file. In a sub-directory called “staging” we have another website running which is totally independent from the website in public_html. How can I address the sub-directory with an .htaccess in order to remove the .html extensions? We are on a apache server with cPanel, shared hosting (Hostgator).

.htaccess in public_html

# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]


</IfModule>
# -- concrete5 urls end --

<IfModule mod_headers.c>    
Header set Access-Control-Allow-Origin *
</IfModule>
#Header set Access-Control-Allow-Origin *

.htaccess in staging

RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [NC,L]

Any (detailed) help or instructions would be highly appreciated!

2

Answers


  1. Just keep the staging/.htaccess, but remove RewriteBase /, because this causes the relative substitution path $1.html to be searched at /$1.html instead of /staging/$1.html.

    The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path.

    You also don’t need the NC|nocase, because the pattern doesn’t contain any “alphabetic” letters.

    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ $1.html [L]
    
    Login or Signup to reply.
  2. It seems that you could use this

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*).html$ /$1 [L,R=301] 
    

    in subdirectory or modify parent htaccess.
    As I tested it at http://htaccess.madewithlove.be/ it works.

    Are your pages real static html pages or html addresses are generated by some CMS’s links system?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search