I’m having a weird issue with mod_rewrite. My website is set up in such a way that the user can access a translated version of the webpage via a URL like example.com/pt/about or just access the normal page like so example.com/about, to accomplish this I have the following in my .htaccess:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(en|pt)/?$ index.php?lang=$1 [NC,QSA,L]
RewriteRule ^about/?$ about.php [NC,QSA,L]
RewriteRule ^contact/?$ contact.php [NC,QSA,L]
RewriteRule ^([A-Za-z]{2})/about/?$ about.php?lang=$1 [NC,QSA,L]
RewriteRule ^([A-Za-z]{2})/contact/?$ contact.php?lang=$1 [NC,QSA,L]
In my development machine I’m running XAMPP 3.2.2 with Apache 2.4.29 and in my production server I’m running Ubuntu 16.04.3 LTS with Apache 2.4.18. In my development machine everything works fine, if I try to visit /about it shows me about.php and if I try /pt/about it translates the page to portuguese as is the correct behavior, but in the production server if I try to visit /about I get a 404 error, but if I try to visit /pt/about it displays the page correctly without any issues.
Why is this happening and how I might correct it?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.