What's the best approach to generate nice URLs using Zend Framework?
Without Zend Framework and with MVC pattern I'd just use .htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [QSA,L]
Then parse the request parameters in PHP.
I'm now using Zend Framework and trying with zend_route in my bootstrap, like suggested here and documented on Zend website .
My task is to convert a request: example.com/pets-new-york
into example.com/index/search/?q=pets%20new%20york
(current)
I can't make it work, how do I manage non existing files (-f) and dirs (-d) like it works in the first .htaccess example? More generally, what's the best approach to create nice URLs with Zend Framework with non-existing directories?
Please try with this. The following code will be create SEO Friendly url
Note: You have to be make sure that rewrite apache module should enabled on your server
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
or
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
Let me know if you need any help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.