[英]How to mask the URL with htaccess in zend framework 1.10
嗨,我必須創建類似“ http://www.contract.com/user/profileview/index/MQ== ”到“ http://www.contract.com/profile/india/MQ== ”的URL 。 我們已經嘗試使用codeignitor進行掩蔽並成功。 但是進入Zend時會拋出錯誤“指定的控制器無效(印度)”。
我們重寫了htaccess規則,以在codeignitor中屏蔽URL。 此處應用相同,但此處不起作用。 我的htaccess代碼是
#php_value magic_quotes_gpc off
RewriteEngine on
Options -Indexes
Options FollowSymlinks
RewriteEngine On
RewriteBase /
#Admin
RewriteRule ^admin(.*)$ public_mvc/admin.php [L]
#RewriteRule ^profile/(.*)/(.*)/(.*)(/|)$ user/profileview/index/$2 [L,NC]
RewriteRule ^profile/(.*)/(.*)/(.*)(/|)$ user/profileview/index/$2 [L,NC]
#RewriteRule ^profile/(.*)/(.*)/(.*)/?$ user/profileview/index/$2 [L,NC,QSA]
# Also Tried Ones. Start
#RewriteRule ^profile/(.*)/(.*)/(.*)/$ /user/profileview/index/$1 [NC,L]
#RewriteRule ^profile/(.*)/(.*)/(.*)/?$ /user/profileview/index/$2 [NC,L]
#RewriteRule ^profile/(.*)/(.*)/(.*) /user/profileview/index/$2 [NC]
#RewriteRule ^/profile/(.*)/(.*)/(.*)/?$ /user/profileview/index/$2 [QSA]
# Also Tried Ones. End
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ public_mvc/index.php
Rewriterule ^$ /home [r=301,nc]
這有什么問題? 我們嘗試了很多類型的選項。 但是所有人都徒勞無功。 您可以在代碼中看到所有這些不同的嘗試。 請幫我這個。
提前致謝。
“ http://www.contract.com/profile/india/MQ== ”
上面的URL可以在htaccess中重寫
方法1; RewriteRule ^ profile /(.*)$ redirectedUrl.php [NC,L]
redirectedUrl.php作為頁面,它應該放在根目錄中,它不能顯示錯誤,需要更改htaccess中的URL!
方法2; 在bootstapper.php上處理重定向到某個控制器,並使用另一個操作
Zend_Controller_Router_Route_Regex
感謝您的支持。 我已經以其他方式實現了目標。 我們已根據需要更改了ZEND路由。 因此,我們有了Auth文件(在每個請求中都會調用它)。 在所有請求中都將調用此文件。 因此,我要做的就是檢查URL,如果URL包含模塊名稱為“ Profile”,那么我已經使用“ setModuleName”,“ setControllerName”,“ setActionName”等設置了模塊,控制器和操作的名稱。
$ModuleName = $request->getModuleName();
$ControllderName = $request->getControllerName();
$ActionName = $request->getActionName();
/*
This condition is added to mask the URL. This is added by Ghanta Kiran on 27-Dec-2013. Start
Example : (From) http://www.contractskills.com/profile/india/username/id ==> (To) http://www.contractskills.com/user/profileview/index/id
*/
if($ModuleName == 'profile')
{
$paramId = $request->getParam('id'); // This is to get the User Id from the URL, to fetch the user profile details.
$request->setModuleName('user');
$request->setControllerName('profileview');
$request->setActionName('index');
$request->setParam('id',$paramId);
}
因此,它將要做的是,如果URL中包含“配置文件”,它將明確設置模塊,控制器和操作。 我對.htaccess進行了很多更改,但最終所有這些努力都變得瘋狂了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.