开发者

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. Thi开发者_运维问答s also disable redirect to the uri with trailing slash.


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

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


This works for me:

RewriteEngine On
RewriteRule ^/$|^(.*)$  /public/$1 [QSA,NC,L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜