skip to Main Content

im working on a simple html/css website in an apache server

i changed urls from www.mydomain.com/about.html to www.mydomain.com/a-propos-de-nous for all fils in main directory with a htaccess file :

Options +FollowSymlinks 
RewriteEngine On 
RewriteRule a-propos-de-nous /about.html

its working perfectly!

but when i try to do the same for files in a sub directory /en , it gives me error 404 :
i created a new file (en.htaccess) in sub directory /en , the content of the file is :

Options +FollowSymlinks 
RewriteEngine On
RewriteBase /en/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule about-us /en/about.html [L]

i expected to have www.mydomain.com/about-us working, but its gives me error 404.

but i have always the 404 error ,
i missed something ?

Thanks for help

2

Answers


  1. Try changing your htaccess rules file to following once. Make sure to clear your browser cache before testing your URLs.

    RewriteOptions InheritBefore
    
    Options +FollowSymlinks 
    RewriteEngine On
    RewriteBase /en/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule about-us en/about.html [L]
    
    Login or Signup to reply.
  2. If you want to rewrite www.mydomain.com/about-us then rewrite rule must go in root .htaccess since there is no /en/ in your original URI. Just change your root .htaccess to this:

    Options +FollowSymlinks 
    RewriteEngine On
    
    RewriteRule a-propos-de-nous about.html [L,NC]
    
    RewriteRule ^about-us en/about.html [L,NC]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search