Home > Software engineering >  Rewrite names of files in a subdirectory with htaccess gives error 404
Rewrite names of files in a subdirectory with htaccess gives error 404

Time:11-25

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

CodePudding user response:

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]

CodePudding user response:

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]
  • Related