PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

[FIXED] Yii 2.0 hiding /basic/web from the URL along with the index.php

 March 03, 2022     .htaccess, php, url-rewriting, yii, yii2     No comments   

Issue

Plenty of information around the net on how to hide the index.php from your Yii 2.0 application URL, however, what I'm trying to do here is to also remove the '/basic/web/' from the URL. /basic/web is the directory from which the application is running and the configuration that I have so far is the following. That goes into the config file:

'urlManager' =>[
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],

And this is my htaccess file that I have within the /web folder:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

So far, so good, I can access something directly calling mysite.com/basic/web/controller/action. What do I need to do though to remove the /basic/web so that the URL becomes just simple mysite.com/controller/action?

Any tips welcome, thanks!

EDIT: I'm looking for a way without touching the apache configuration file as I don't have access to it.


Solution

You should define your apache configuration in another way. Your site should point to {folder}/basic/web and not to {folder}.

Because you changed the requirements:

For a cpanel setup you should:
1) remove the silly basic folder, what is the point of it anyway? Just because Yii installs that way does not mean you have to keep it. So move everything 1 level up.
2) Rename web to public_html make sure you rename it in some files too (config/bootstrap comes to mind).

Yes you can do it with .htaccess but you should not have the files exposed to the internet, just your web folder should be exposed so I am not giving you that solution because it is not a good one.



Answered By - Mihai P.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing