0

我有一个后端和前端分开的 yii 应用程序。我正在尝试制作友好的网址。我尝试了一些在线工具但无法正确所以我想要这个网址

  • 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 前端的规则是:这个 url:

  • 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 在根目录下

4

2 回答 2

1

我想问题出在RewriteBase.

您可以在目录中的 .htaccess 文件中尝试此操作/abs

根据最后的 OP 评论更新: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]
于 2013-02-28T05:48:45.753 回答
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]
于 2013-02-28T06:07:33.627 回答