How to remove index.php from url in Zend Framework

2019-08-30 10:30发布

I am developing this app using Zend Framework 1.12. I wan to get rid off the index.php using .htaccess. Right now my url looks like this:

http://foo.com:10080/Reports_Century/public/index.php/reports/neworders

I want to be able to look like this

http://foo.com:10080/Reports_Century/public/reports/neworders

Is it possible? my htaccess looks has the following lines:

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

thank you.

5条回答
在下西门庆
2楼-- · 2019-08-30 11:09

Have your public/.htacess like this:

RewriteEngine On
RewriteBase /Reports_Century/public/

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(.+)$ index.php/$1 [L]
查看更多
爷、活的狠高调
3楼-- · 2019-08-30 11:09

You also need to activate "AllowOverride All" for your directory in apache2/sites-enabled/default:

    <Directory /var/www/html/public>
            AllowOverride All
    </Directory>
查看更多
再贱就再见
4楼-- · 2019-08-30 11:10

Version without index.php is default in Zend. You don't have to change default .htaccess. I bet you didn't enabled rewrite module in apache* or disabled rewriting in config.

* copy rewrite.load file to mods-enabled folder in apache (on ubuntu it's in /etc/apache)

查看更多
乱世女痞
5楼-- · 2019-08-30 11:23

Try adding this right below RewriteEngine On

RewriteRule ^index\.php/(.+)$ /public/$1 [L,R]
查看更多
三岁会撩人
6楼-- · 2019-08-30 11:25

finally found where the issue was. The problem was the $1 after index.php/.

the final .htaccess is:

RewriteEngine On
RewriteBase /Reports_Century/public/

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(.+)$ index.php [L]

@Anubhava giving you a plus one for speding the time and helping me with the solution.

查看更多
登录 后发表回答