Php rewrite url through .htaccess

偶尔善良 提交于 2019-12-19 07:46:09

问题


I want to rewrite some url by using .htaccess rewrite

I have url something like this:

domain.com/app/index.php/appmedia/default/login

and want to rewrite users to

domain.com/app/index.php/zurmo/default/login

So, what will happen is users will see appmedia in browser but in the backend it will access zurmo

I'm new to php and have read some blogs like this have no luck

Also, have tried this

RewriteEngine On
RewriteRule ^app/index.php/appmedia/default/login.*$ http://domain.com/app/index.php/zurmo/default/login [R=301,L]

it says The page isn't redirecting properly

Edit of .htaccess file

RewriteEngine On
RewriteRule ^app/index.php/appmedia/default/login.*$ http://mydomainx.com/app/index.php/zurmo/default/login [R=301,L]

回答1:


You can't use a [R=301] and expect the URL not to change. R means redirect. So it will change to the URL you told it to. For an internal rewrite you need to leave that off.

If you have .htaccess in your document root then you should be able to do this. I don't know how your setup is but this should rewrite the URI.

Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/index.php/appmedia/default/login/?$ /app/index.php/zurmo/default/login [L]

If you are using yii framework do like this:

'urlManager' => array (
 'class' => 'application.core.components.ZurmoUrlManager',
 'urlFormat' => 'path',
'caseSensitive' => true,
'showScriptName' => true,
'rules' => array(
 // Begin Not Coding Standard
 // API REST patterns
 array('zurmo/default/login','pattern' => 'appmedia/default/login', 


来源:https://stackoverflow.com/questions/29255578/php-rewrite-url-through-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!