【发布时间】:2014-03-11 21:54:34
【问题描述】:
我正在使用 Zend Framework 2 和随附的 .htaccess 进行 URL 重写,如下所示:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
此外,我还定义了如下路由:/customers/8080/edit。现在我需要这条路线也可以通过/customers/edit/8080 访问。额外的 URL 应该是一个别名而不是一个简单的重定向。
因为我的路由已经非常复杂,所以在module.config.php 中重写我的路由确实是没有选择的。我认为实现这一点的最简单方法是在我的.htaccess 中添加重写条件并定义路由/customers/edit/8080 只需映射到/customers/edit/8080。
由于 ZF 将每个 URL 重定向到 index.php,我一直在定义我的别名路由。
任何建议都会很棒(:
【问题讨论】:
标签: php .htaccess zend-framework mod-rewrite zend-framework2