How to remove index.php from url in Zend Framework

2019-08-30 11:19发布

问题:

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.

回答1:

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]


回答2:

Try adding this right below RewriteEngine On

RewriteRule ^index\.php/(.+)$ /public/$1 [L,R]


回答3:

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)



回答4:

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.



回答5:

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

    <Directory /var/www/html/public>
            AllowOverride All
    </Directory>