0

Good morning, I have a Virtual Host configured on an Apache2 server. The mod_rewrite module is active and functional.

I tested regular expressions on the site https://regex101.com/ and it behaves like I expect.

I tested the .htaccess file on the https://htaccess.madewithlove.be/ site and it works correctly.

I don't understand why, when I try it on the apache server it doesn't work.

Here is the complete .htaccess file

.htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(assets|locale)/(.*)$  user/$2/$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(/{0,1})user/([^/]+)(/?.*) user/$2.html [QSA,L]

Virtual host Configuration

Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted

Website structure

mywebsite.local
    user/
        - .htaccess
        - index.html
        - app.html

Tested URL

http://mywebsite.local/user/index/
http://mywebsite.local/user/app/
http://mywebsite.local/user/app/dashboard/
http://mywebsite.local/user/app/planningWeek/current/
http://mywebsite.local/user/app/task/taskId/day/month/year/

What I'm expected

http://mywebsite.local/user/index/
go to index.html (it works)

http://mywebsite.local/user/app/
go to app.html (it works)

http://mywebsite.local/user/app/dashboard/
it must go to app.html but I have this error
"The requested URL /user/app.html/dashboard was not found on this server."

I don't understand why the regular expression is valid and the .htaccess file from the sites indicated works, but if I load it on the server no.

Thanks

Luca Romano
  • 116
  • 7
  • the very first thing you need to do is change `+MultiViews` to `-MultiViews` (because it messes with your requests in more ways than you can imagine) – Dusan Bajic Apr 17 '19 at 13:28
  • Next, you probably want to move `.htaccess` to the root folder of your website – Dusan Bajic Apr 17 '19 at 13:30
  • (in fact, since you have access to apache .conf files, [you should not use .htaccess at all](https://httpd.apache.org/docs/2.4/howto/htaccess.html#when)) – Dusan Bajic Apr 17 '19 at 13:31

1 Answers1

0

It seems like mod_rewrite is just substituting app for app.html in your example, thus generating /user/app.html/dashboard out of /user/app/dashboard.

If your .htaccess file works in the website you've tested it, could it be that there are any other components interfering in the request?

Maybe the rewrite logs can lead you to an answer? For further information see this Stackoverflow answer.

Hope it helps, kind regards.