[英]Zend Framework 2 URL Rewrites
我正在使用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
實際上沒有辦法在module.config.php
重寫我的路由。 我認為實現這一目標將是添加重寫條件,我最簡單的方法.htaccess
和定義路由/customers/edit/8080
簡單映射到/customers/edit/8080
。
由於ZF將每個URL重定向到index.php
我不得不定義別名路由。
任何建議都很棒(:
我正在處理一個非常類似的問題,但是我繼承了Zend安裝,因此我不知道“開箱即用”安裝的外觀。
我(某種程度上)通過在application.ini
文件中添加“ baseURL”參數解決了我的問題。 在這里查看我的問題和解決方案,可能會有幫助。 將Zend Framework站點移至新主機-“找不到錯誤頁面”
注意:我對我的結果不是100%滿意。 我仍在努力,但距離越來越近。
通過簡單地將文字RewriteRule
添加到.htaccess
文件即可解決此問題。 這是我最初嘗試使此工作正常進行的工作,但我一直沒有在模式部分忽略省略號。
這就是我想出的:
RewriteRule ^customers/([0-9]+)/base/edit/([0-9]+)/?$ /customers/$1/edit/base/$2 [NC,L,P]
考慮指定[P]
標簽,如果不應該更改URL,則該標簽將請求作為代理請求處理。
另請參閱此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.