PHP通过.htaccess重写URL [英] Php rewrite url through .htaccess

查看:70
本文介绍了PHP通过.htaccess重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 .htaccess 重写

I want to rewrite some url by using .htaccess rewrite

我的网址是这样的:

并希望将用户重写为

因此,将要发生的是用户将在浏览器中看到appmedia,但在后端它将访问zurmo

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

我是php的新手,并且已经阅读了一些博客,例如没有运气

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

还尝试过

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

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

推荐答案

您不能使用[R=301]并且期望URL不变. R表示重定向.因此它将更改为您告知的URL.对于内部重写,您需要将其保留.

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.

如果您在文档根目录中具有.htaccess,则应该可以执行此操作.我不知道您的设置如何,但这应该重写URI.

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]

如果您使用的是 yii框架 ,请执行以下操作:

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', 

这篇关于PHP通过.htaccess重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆