2013-02-28 53 views
0

我有一个yii应用程序,它具有独立的后端和前端。我正在尝试制作友好的网址。 我已经尝试了一些在线工具,但不能让它正确 所以我希望这个网址后端/前端应用程序的htacess重写规则

  • http://mydomain.lc/abs/admin/some/crazy/urls(for example some/crazy/urls can be admin/index)

将被改写为:

  • http://mydomain.lc/abs/backend.php/some/crazy/urls(because this url works directly)

而且我也有前端网站,但他们都在同一个项目中,因此他们共享.httacess。 对的.htaccess的前端规则是: 这个网址:

  • http://mydomain.lc/abs/some/crazy/urls(some can not be admin here, so we can differentiate btw fron and back end)

应该

  • http://mydomain.lc/abs/index.php/some/crazy/urls

我:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^abs/admin/?(.*?)$ abs/backend.php?url=$1 [QSA,L] 

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(?!abs/admin\/)(.*?)$ abs/index.php?url=$1 [QSA,L] 

</IfModule> 

上述脚本无法正常工作。 根目录在abs文件夹下,并且根目录下的.htaccess为

在此先感谢。

+0

哪一个不工作?第一或第二个RewriteRule?甚至是两者? – 2013-02-28 04:20:46

+0

根据你的说法,root应该是'http:// mydomain.lc /'不是'http:// mydomain.lc/abs /'。请解释并确认.htaccess文件的位置。 – 2013-02-28 04:28:26

+0

root在这里:'http:// mydomain.lc/abs /',因为我没有欠我放的地方,所以项目位于(开始spot index.php)在abs下并且.htaccess在那里,但是不直接在http:// mydomain.lc/thanks – Elbek 2013-02-28 04:47:19

回答

1

你不必改变除了RewriteBase /什么RewriteBase /abs

RewriteEngine On 
RewriteBase /abs 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^admin/?(.*?)$ backend.php?url=$1 [QSA,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(?!admin\/)(.*?)$ index.php?url=$1 [QSA,L] 
+0

作为一种魅力。谢谢。 – Elbek 2013-02-28 15:36:13

1

我想问题是与RewriteBase

更新根据最后OP评论:

您可以在.htaccess文件中/abs目录试试这个this one is correct: backend.php/some/crazy/urls

Options +FollowSymlinks -MultiViews 
RewriteEngine On 
RewriteBase /abs 

# Backend admin 
RewriteCond %{REQUEST_URI} !backend\.php [NC] 
RewriteRule ^admin(.*) /backend.php/$1 [QSA,L,NC] 

# Frontend 
RewriteCond %{REQUEST_URI} !index\.php  [NC] 
RewriteCond %{REQUEST_URI} !admin   [NC] 
RewriteRule ^(.*)  /index.php/$1 [QSA,L,NC] 
+0

感谢您的贡献。我们可以纠正这个规则来重写这个:backend.php/some/crazy/url而不是admin/backend。 PHP的?url =感谢一个男人。 – Elbek 2013-02-28 05:51:40

+0

它被纠正了。检查我更新的答案。 – 2013-02-28 05:52:11

+0

我有'%1'而不是'$ 1',我也纠正了。 – 2013-02-28 05:54:05