I have created a .htaccess file in my root folder that contains the following code:
-RewriteEngine On
Add a comment to this line
-RewriteCond %{REQUEST_URI} !^/web
-RewriteRule ^/?([^/]+)$ /web/$1 [L]
but it doesn't work as expected. I also have a .htaccess file in web folder that contains the following code:
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 am I doing wrong, here?
Put in .htaccess:
RewriteRule . /web/index.php
Or
RewriteRule . /basic/web/index.php
EDIT.
I find better solution. Put in .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
Change domain.com to your domain.
should change the AppAsset public $css path
Add .htaccess outside of the web folder
AddDefaultCharset UTF-8
Options +FollowSymLinks
IndexIgnore */*
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
Add following in config/web.php
'urlManager' => array(
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
move index.php from inside of the web folder to outside and change these 3 lines
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/config/web.php');
This is working for me in both development and production.
Related
e.g. my-domian/yyy yyy can't be recognized by my routes.php
I accidentally delete the content in my .htaccess file.
The routes.php file (router file) no longer route my site properly.
routes.php:
Router::scope('/', function ($routes) {
//this one works
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
//these two routes no longer work
$routes->connect('/survey', ['controller' => 'Surveys', 'action' => 'get']);
$routes->connect('/scenario', ['controller' => 'Scenarios', 'action' => 'get']); });
my-domain/ works.
my-domain/survey?xx=3 no longer works.
404 error I got for my-domain/survey?xx=3 :
File does not exist: /home/nexusuto/public_html/survey
my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*/)?\.svn/ - [F,L]
ErrorDocument 403 "Access Forbidden"
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
</IfModule>
Please help me... I have been stuck for a long time :(((( I just want to resume the basic use of .htaccess file i.e. I can route my-domain/survey to my survey controller..
If you do not know how to write a .htaccess rules, then simply downloading the same version of CakePHP and replace .htaccess in your web application.
If you have not modified the file routes.php just create .htaccess again
Try with this .htaccess structures:
ROOT .HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app/ .HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
app/webroot/ .HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/webroot
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
But if you modify routes file maybe you should try this:
$routes->connect('/survey/*', ['controller' => 'Surveys', 'action' => 'get']);
The URL is a normal slash delimited string, but can also contain a
wildcard (*) or Route Elements. Using a wildcard tells the router that
you are willing to accept any additional arguments supplied. Routes
without a * only match the exact template pattern supplied.
http://book.cakephp.org/2.0/en/development/routing.html#connecting-routes
When you google for this problem, one can find lots of simular problems but no single solution.
I've got this website:
www.website.com
My CakePhp 3.x project is located in this directory
www.website.com/project
Sessions are used in a previous project so I have to customise the session in app.php in order to access them
'Session' => [
'defaults' => 'php',
'cookie' => 'PHPSESSID',
'timeout' => '20000',
'ini' => [
'session.cookie_domain' => '.website.com',
'session.save_path' => '/var/www/clients/client1/web/tmp/',
]
],
!! All is fine browsing http://www.website.com/project It keeps the session intact!!
In htaccess I make the /project folder invisible so:
http://www.website.com/project becomes http://www.website.com/
http://www.website.com/project/start becomes http://www.website.com/start
...
Now; http://www.website.com/ and http://www.website.com/start are loosing my sessions
This is my htaccess-file:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !website.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^website\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.website\.com$
RewriteCond %{HTTP_HOST} !^www\.website\.com$
RewriteRule (.*) http://www.website.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
#rewrite previous project to root
RewriteRule ^/?$ "http\:\/\/www\.website\.com\/sys" [R=301,L]
#do nothing with these urls
RewriteCond %{REQUEST_URI} !^/portret/.*$
RewriteCond %{REQUEST_URI} !^/temp/.*$
RewriteCond %{REQUEST_URI} !^/tempcs/.*$
RewriteCond %{REQUEST_URI} !^/tempmail/.*$
RewriteCond %{REQUEST_URI} !^/tempsoc/.*$
RewriteCond %{REQUEST_URI} !^/tempzip/.*$
RewriteCond %{REQUEST_URI} !^/web/.*$
#disable project folder to make it nice
RewriteRule (.*) /project/$1 [QSA,L]
#fixing some pains-in-the-ass
Redirect 301 /FDM http://old-website/web/index1.php?ID=FDM
Redirect 301 /GM http://old-website.be/web/index1.php?ID=GM
Redirect 301 /FC http://old-website.be/web/index1.php?ID=FC
#set the root
DirectoryIndex project/search/start
Some debug-info:
session_get_cookie_params
Array ( [lifetime] => 0 [path] => /project/ [domain] => .website.com [secure] => [httponly] => 1 )
CakePhp Debugkit Cookie Request on a page without /project
__unameb00ce0-152452f3c4a-10c277e4-12
PHPSESSID j1guvr5armlfpa7aa64aa9lfe1
_gaGA1.2.1776275125.1452677383
_gat1
CakePhp Debugkit Cookie Request on a page with /project
search Q2FrZQ==.MWQ3MzRhMWY3YWVmMzY0OGEzN2QwODFjMmY0MDE3NTdiOTI4OTQ5NDYxNmNhNmYwNzMyMjRmOTExNDA5NDJlOR+xldRH1lAaIbKGzowwWjtleNpkY/NYKZjft08u3Q8C
PHPSESSID 3amnr19lag1l0s7v5f20us4rq7
language Q2FrZQ==.ZDdjOWQ2NmI2ZDhiNWYzZGM2Zjg4MjRkM2NjMzRjMGRiMmM3NzM4MmEzMzRmZTFkNDI2NDhkY2U4MjBhOGZjM/ARPIqb98q5NwFN9JLi/HelqGCM6V3bsdCFlxxOkI/z
__unameb00ce0-152452f3c4a-10c277e4-12
_gat1
_gaGA1.2.1776275125.1452677383
The following settings worked for me:
'Session' => [
'defaults' => 'php',
'ini' => [
'session.cookie_path' => '/'
]
],
How to remove "index.php" and also wants to remove "?r=". I want to make URLs user friendly.
Do these 3 steps:
Enable Url re-writing on Apache.
Place .htaccess on root of your project
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
In your configuration protected/config/main.php set showScriptName to false like this to your url manager components >> urlManager
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
'showScriptName'=>false,
)
1) enable your urlManager in protected>>config>>main.php by adding these line to the array:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
'showScriptName'=>false,
),
2) The .htaccess file should be in the site root in the same of index.php level and should be like that:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
# otherwise forward it to index.php
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]
3) make sure that your Apache configuration AllowOverride All not None
In my test application, I'm trying to remove index.php from the url. I can access the root page like so http://localhost/trackstar/ instead of http://localhost/trackstar/index.php, but as soon as I'm trying to access another page like http://localhost/trackstar/project or any other page I'm always ending up at the index.php page. Opening http://localhost/trackstar/index.php/project works however.
I'm using WAMP server. Configuration as below.
Rewrite module in apache is enabled.
Config main:
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'commentfeed' => array('comment/feed', 'urlSuffix' => '.xml', 'caseSensitive' => false),
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'showScriptName' => false,
),
.htaccess in root folder of project:
Options +FollowSymlinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I've also added in httpd.conf, although not really necessary I think:
<Directory "c:/wamp/www/TrackStar/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
I've tried several combinations of extra parameters in .htaccess, but I keep getting redirected to my index.php page.
Any thoughts as to why this doesn't work?
Edit:
Since I'm being redirected, the checks in RewriteCond don't succeed, in other words the REQUEST_FILENAME isn't found as a directory or file. Maybe there's something off in my directory structure?
The TrackStar\protected\views\project directory, for example is the page I'm trying to access via http://localhost/trackstar/project. My Yii framework files are in a directory above the www folder.
Try to add into .htaccess following after RewriteEngine on:
RewriteBase /trackstar/
The problem in: when not found file it redirects to http://localhost/index.php, in request http://localhost/trackstar/index.php/project file index.php is found and it works correctly
UPDATED:
Try modify your urlManager settings (add /trackstar/):
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'commentfeed' => array('comment/feed', 'urlSuffix' => '.xml', 'caseSensitive' => false),
'/trackstar/<controller:\w+>/<id:\d+>' => '<controller>/view',
'/trackstar/<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'/trackstar/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'showScriptName' => false,
),
You can do that with 2 simple steps.
Configure the 'urlManager' at config/main.php to look like this
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
),
Add an .htaccess file at the root of the application with the following code
Options +FollowSymLinks
IndexIgnore */*
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
Thats it!
Can you try:
.htaccess in root folder of project:
Options +FollowSymlinks -MultiViews
IndexIgnore */*
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.*?)index\.php$ /$1 [L,NC,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
change your config/main.php like below:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
then place your htaccess file on base directory with protected folder (it may be inside protected folder) place below code to your htaccess file
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
or try with this---
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
done...hope it will work
My yii application was installed in virtual host(http://yii.loc) (WAMP).
I need to remove index.php from url. But only http://yii.loc url works, the other pages says "Not Found".
'urlManager'=>array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '/',
'<controller:\w+>/ <action:\w+>' => '/',
),
.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
Check out the settings of Apache. I had same problems when the rewrite rule was disabled.
Go to WAMP icon->Apache modules->rewrite_module and turn it on
Than try to restart your WAMP & aplication in browser)
Got a solution. By mistake I have changed the .htaccess which are located in protected folder. So I restored the file
deny from all
The I created a new .htaccess file in the root directroy and add
Options +FollowSymLinks
IndexIgnore */*
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
And now it works.