0

I have ProjectsController.php in which I have actionIndex

In my main.php file which is in frontend/config/main.php I have done routing as below.

 'components' => [
    'urlManager' => [
        'showScriptName' => false,
        'enablePrettyUrl' => true,
        'rules' => [
            'projects'=>'projects/index',
         ],
       ],  
     ]

Which means I am trying to redirect to index action in projects controller with url /projects. I am able to access in my localhost like localhost/myproject/projects, but whereas when I try to access the same in live like www.myproject/projects/ it is redirecting to home page and if I try to access like www.myproject/frontend/web/projects/index then I am able to redirect to the correct page.Not only this particular action and controller, all the other routing mentioned in main.php are redirecting to home page.

Below is my .htaccess file code in my root file '/'

    # prevent directory listings
#Options -Indexes
#IndexIgnore */*

# follow symbolic links
#Options FollowSymlinks
RewriteEngine on
#RewriteCond %{REQUEST_URI} ^/common/css/
#RewriteRule ^common/css/(.*)$ common/css/$1 [L]
#RewriteCond %{REQUEST_URI} ^(?!.*/web/)
#RewriteCond %{REQUEST_URI} !^/web/
#RewriteRule .* backend/web/index.php [L]
#RewriteCond %{REQUEST_URI} ^(?!.*/web/)
#RewriteRule ^(.*)?$ backend/web/$1 [L,PT]

#RewriteCond %{REQUEST_URI} !^/frontend/web/
#RewriteRule backend/(.*)$ backend/web/index.php [L]
#RewriteRule ^frontend/(.*)$ frontend/web/$1 [L]
#RewriteBase /
RewriteRule ^common/(.*)$      common/$1   [QSA,L,NC]
RewriteRule ^frontend/images/(.*)$      frontend/images/$1   [QSA,L,NC]
RewriteRule ^(.*)$      frontend/web/index.php/$1   [QSA,L,NC] 

#RewriteCond %{REQUEST_URI} ^frontend/(assets|css|js|images|themes)
#RewriteRule ^frontend/images/(.*)$      frontend/images/$1   [QSA,L,NC]

#RewriteCond %{REQUEST_URI} ^/frontend/web/projects/$
#RewriteRule frontend/projects/(.*)$ frontend/web/index.php/projects/$ [L]
#RewriteCond %{REQUEST_URI} ^(?!.*/themes/)

#RewriteCond %{REQUEST_URI} ^/(assets|js|images|themes|uploads)
#RewriteRule ^themes/(.*)$ backend/web/themes/$1 [L]
#RewriteRule ^images/(.*)$ backend/images/$1
#RewriteRule ^css/(.*)$ backend/web/css/$1 [L]



#RewriteRule ^(.*)?$ backend/themes?$ [L,PT]
#RewriteRule ^(.+)?$ frontend/web/$1
#
#RewriteCond %{REQUEST_URI} !^/backend/(assets|css|themes)/
#RewriteRule .* backend/themes/$1 [L]  

#Options -Indexes
#RewriteEngine on


#
#RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
#RewriteCond %{REQUEST_URI} !index.php
#RewriteRule frontend/web(.*) frontend/web/index.php [L]

#RewriteCond %{REQUEST_URI} ^/(assets|css|js|images|themes)
#RewriteRule ^assets/(.*)$ backend/web/assets/$1 [L]
#RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
#RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
#RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
#RewriteRule ^themes/(.*)$ frontend/web/themes/$1 [L] 

Below is the .htaccess from /frontend/web/

RewriteEngine on

# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

Please help. I am unable to resolve this. I am actually not able to understand the cause.

4
  • what server you are using ? Commented Oct 1, 2019 at 10:26
  • What is the path of your .htaccess file? Do you have urlManager component in your common/main.php file also? Commented Oct 3, 2019 at 9:10
  • @MAZ No, I do not have urlManager in common/main.php The .htacces code which I have mentioned above is from my root file i.e '/'. Also I have edited my query and added .htacces file of frontend/web/.htaccess Commented Oct 3, 2019 at 10:24
  • @KandarpPatel I am using godaddy server Commented Oct 3, 2019 at 10:25

2 Answers 2

1

You need to create two .htaccess. One in your project root folder and another in your frontend/web folder.

Please follow the steps of Anant Singh's answer of this question.

Yii2:-Pretty URL's are formed, but not working (says 404 “NOT FOUND”)

I hope It will help.

Sign up to request clarification or add additional context in comments.

Comments

0
RewriteRule ^(.*)$      frontend/web/index.php/$1   [QSA,L,NC] 

Change above rule in your root .htaccess to

RewriteRule ^(.*)$      frontend/web/$1   [L,NC] 

2 Comments

is it the godaddy shared hosting ?
well in that case. seems this question might help you stackoverflow.com/questions/27736282/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.