Elbek
Elbek

Reputation: 3484

htaccess rewrite rule for backend/frontend app

I have a yii app that has separate back end and front end. I am trying to make friendly url. I have tried some online tools but could not get it correct So I want this url

will be rewritten to:

And I have also front end site but they are both in the same project so they share .httacess. the rule for .htaccess for front end is: this url:

should be

I have:

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

the above script is not working. Root is under abs folder and .htaccess in the root

Upvotes: 0

Views: 1708

Answers (2)

Odiljon Sattarov
Odiljon Sattarov

Reputation: 104

You do not have to change anything except RewriteBase / to 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]

Upvotes: 1

Felipe Alameda A
Felipe Alameda A

Reputation: 11809

I guess the problem is with the RewriteBase.

You may try this in the .htaccess file in /abs directory:

Update according to last OP comment: 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]

Upvotes: 1

Related Questions