Yii Framework Forum: Yii 2.0 - Basci App - I Miss The .htaccess File. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii 2.0 - Basci App - I Miss The .htaccess File. I can't hide the subfolder in my redirected URL by the .htaccess

#1 User is offline   blaces 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 06-April 12

Posted 02 October 2013 - 06:08 PM

Hi,

I am waiting for the Yii2.0. And I downloaded the basic yii 2.0 app from github. I like the directory structure. But I have a problem: I miss the .htaccess file.

I can't hide the subfolder in my redirected URL by the .htaccess

I saw some solutions here, but they didn't help me. My index.php is here: http://localhost/bas.../web/index.php.

And I would like to aim that If I type the http://localhost/basic-2, the browser redirect me to the http://localhost/basic-2/web/index.php path, but in the browser the URL be the http://localhost/basic-2/index.php address. So I would like to remove (or hide) the web subfolder from the URL.

I have seen many solutions here... but nothing :(, Now I have this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/web/$1 -f [NC]
RewriteRule ^([^/]+)$ /web/$1 [P,L,QSA]

But this is only list the folders and files... and not make redirect to the subfolder.

This can redirect, but doesn't hide the web folder from the URL.

RewriteEngine On
RewriteRule ^$ web [L]

Edit1 I found another rules:

RewriteEngine On
RewriteRule ^$ web/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ web/$1

This can redirect! But this rule doesn't hide(or remove) the web folder still...

Anybody or the staff have got any solution? :)

I like the Yii2.0, but I can't wait too much. :)
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,225
  • Joined: 17-January 09
  • Location:Russia

Posted 03 October 2013 - 04:29 AM

.htaccess for 2.0 should be the same as for 1.1.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#3 User is offline   blaces 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 06-April 12

Posted 03 October 2013 - 12:24 PM

View Postsamdark, on 03 October 2013 - 04:29 AM, said:

.htaccess for 2.0 should be the same as for 1.1.


Yes I tired with it (1.1.). But it doesn't work for me. Okay, I continue find other solutions.
0

#4 User is offline   gerrit_ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 06-February 12

Posted 10 December 2013 - 05:47 PM

I would also like to know how to get rid of the "web in a url"

current:
http://localhost/basic/web/about.html

I would like:
http://localhost/basic/about.html

config:

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'suffix' => '.html',
            'rules' => [
                '' => 'site/index',
                '<action>'=>'site/<action>',
            ],


web/.htaccess:
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


What do I need to do?
0

#5 User is offline   iJackUA 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 30-May 12
  • Location:Ukraine, Kharkiv

Posted 11 December 2013 - 02:30 AM

You should create VirtualHost in Apache and set DocumentRoot dir to your "....../basic/web" dir (full system path).
Also you will need to add virtual local domain to your system "hosts" file (domain should be linked to 127.0.0.1 IP).
you will not be able to get rid of basic/web/ while you use general http://localhost/ domain name
0

#6 User is offline   gerrit_ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 06-February 12

Posted 11 December 2013 - 10:41 AM

Isn't it just a setting in the config that prevents the urls being prefixed with that folder name?
0

#7 User is offline   iJackUA 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 30-May 12
  • Location:Ukraine, Kharkiv

Posted 12 December 2013 - 05:01 AM

No, there is a setting 'showScriptName' => false, that will hide "index.php" from url
but you cant hide those part with subfolders while you use "localhost"
0

#8 User is offline   klod 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 14-February 11

Posted 05 August 2014 - 08:43 AM

For Basic Applications:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if request dosn't start with web add it
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule (.*) /web/$1

# if file or directory dosn't exists go to /web/index.php 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php 


For Advanced Applications:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on



# if request begins with /admin remove admin and ad /backend/web/
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin\/?(.*) /backend/web/$1

# other requests add /frontend/web/$1
RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web|admin)
RewriteRule (.*) /frontend/web/$1

# if frontend request 
RewriteCond %{REQUEST_URI} ^/frontend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /frontend/web/index.php 

# if backend request
RewriteCond %{REQUEST_URI} ^/backend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /backend/web/index.php 


1

#9 User is offline   yiipii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 30-July 11
  • Location:France

Posted 18 August 2014 - 06:28 PM

Don't forget that the .htaccess file needs to go in the web folder, not in the project root (or whatever you rename web to)
0

#10 User is offline   realtebo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 837
  • Joined: 03-October 12
  • Location:Ferrara

Posted 31 October 2014 - 09:07 AM

please, can you copy/paste the right .htaccess of provide us a link where we can find it?

I've the same problem and actually I'm stopped at the stage where my virtual host domain (web.app.it) open me the folders/files dir and do not execute the index.php ...
Il computer non ragiona, ma ha sempre ragione.
Ricordalo quando fai il debug
0

#11 User is offline   Nenad Zivkovic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 14-March 14
  • Location:Serbia

Posted 31 October 2014 - 09:13 AM

This is minimum that should work.

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

freetuts.org - free web development tutorials - yii2 and more

Improved advanced template

Improved basic template
0

#12 User is offline   realtebo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 837
  • Joined: 03-October 12
  • Location:Ferrara

Posted 31 October 2014 - 09:44 AM

I tried this

<VirtualHost *:80>
   ServerName web.app.it
   DocumentRoot "C:\xampp\htdocs\advanced\frontend\web"
</VirtualHost>


and this into advanced\common\config\main.php

<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
    ],
];



Then I added an .htaccess to frontend\web

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


AND NOW WORKS !!!

Thanks
Il computer non ragiona, ma ha sempre ragione.
Ricordalo quando fai il debug
0

#13 User is offline   Scott_Huang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 18-July 13
  • Location:Xiamen, China

Posted 01 November 2014 - 07:49 AM

You can try Kartik-v template, he publish both basic and advanced template, can resolve your issue, thx.

Kartik-v practical basic template
0

#14 User is offline   realtebo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 837
  • Joined: 03-October 12
  • Location:Ferrara

Posted 03 November 2014 - 11:40 AM

I'll not do it.

Before: Learn to manually do the thing
Then: Choose a faster way
Il computer non ragiona, ma ha sempre ragione.
Ricordalo quando fai il debug
0

#15 User is offline   EndErr 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 05-June 12

Posted 27 November 2014 - 06:05 AM

Is there a solution for nginx?
0

#16 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,225
  • Joined: 17-January 09
  • Location:Russia

Posted 27 November 2014 - 08:26 AM

nginx should work out of the box w/o any extra files. For config check official guide, it's there.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#17 User is offline   duri 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 188
  • Joined: 18-December 14
  • Location:Bosnia and Herzegovina

Posted 08 May 2015 - 08:30 AM

View Postrealtebo, on 31 October 2014 - 09:44 AM, said:

I tried this

<VirtualHost *:80>
   ServerName web.app.it
   DocumentRoot "C:\xampp\htdocs\advanced\frontend\web"
</VirtualHost>


and this into advanced\common\config\main.php

<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
    ],
];



Then I added an .htaccess to frontend\web

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


AND NOW WORKS !!!

Thanks


Tested, it is working fine.
The point is to understand!

Developers: CODE EPICENTER

0

#18 User is offline   Alex_Omeltchuk 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 21-October 16

Posted 21 October 2016 - 02:56 PM

Thank you a lot!!!
I had 404 on all over the pages, only index.php worked.
I created the .htaccess in /sitename/web directory with the text below and it helped me. THX GUYS!

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users