Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirects unexpectedly to folder

I have strange for me problem. I'm developing Zend Framework application and have this file structure:

/
/application/
/public/
/public/.htaccess
/public/index.php
/public/js/
/public/style/
/public/profile/
/.htaccess

My domain point to folder /

When I enter the address example.com/profile/ it goes to the controller profile and this is good. When I enter the address example.com/profile the server redirects me to: example.com/public/profile/

I would like to have a solution that whenever I request: example.com/profile/ or example.com/profile

The same page will be rendered but second version gives me a redirect and I don't know why.

The /.htaccess file is:

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

The role of this file is to route all traffic from / to /public but without any redirects.

The /public/.htaccess file is:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Can anybody help me with this? Thanks.


I fixed this. Here is the solution if somebody have the same problem: To fix this you have to set the following options and disable DirectorySlash

Options -Indexes FollowSymLinks
DirectorySlash Off

Now Apache shouldn't add trailing slashes at the end of uri when you pointing to directory. This also disable redirect to the uri with trailing slash.

like image 238
Marcin Avatar asked Nov 13 '22 20:11

Marcin


1 Answers

Optionally match the last /. Change your .htaccess file to this:

RewriteEngine On
RewriteRule ^(.*)/?$ public/$1 [L]
like image 129
Michael Irigoyen Avatar answered Jan 01 '23 22:01

Michael Irigoyen