Phalcon keeps using index.phtml for different Controllers - phalcon

I'm new to Phalcon and I like the framework but I have problems with links. I use phalcon version 0.6.1 and XAMPP 1.8.1 that has vhosts set to xampp/htdocs/test where my phalcon test is.
I have been following the tutorial and came to a problem. When I use links to load other controllers the adress bar shows the correct path but as far as I can see the index.phtml get loaded every time. I uploaded the files here so you can see for yourselves.
It doesn't matter if I use Tag::LinkTo() or since it doesn't change.
edit:
I followed the instructions, removed the .htaccess files from the /test and /test/public directories to move the to httpd.conf. At the end of it I added
<Directory "C:/xampp/htdocs/www/test">
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</Directory>
<Directory "C:/xampp/htdocs/www/test/public">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</Directory>
and modified my httpd-vhosts.conf like this
ServerAdmin admin#example.host
DocumentRoot "C:/xampp/htdocs/test/public"
DirectoryIndex index.php
ServerName example.host
ServerAlias www.example.host
<Directory "C:/xampp/htdocs/test/public">
Options All
AllowOverride All
Allow from all
</Directory>
The page loads but the absolute links like /public/css/bootstrap.min.css don't work and when I click the link it gives me an error 404 and says Object not found. I modified the files like this:
<Directory "C:/xampp/htdocs/test">
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</Directory>
<Directory "C:/xampp/htdocs/test/public">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</Directory>
and
ServerAdmin admin#example.host
DocumentRoot "C:/xampp/htdocs/test"
DirectoryIndex index.php
ServerName example.host
ServerAlias www.example.host
<Directory "C:/xampp/htdocs/test">
Options All
AllowOverride All
Allow from all
</Directory>
But that brings me to my original problem that when I click the link it loads index.phtml again even though it says localhost:8005/sample in the URL.

It looks like your Apache configuration is not allowing reading the .htaccess file:
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName phalcon.test
DocumentRoot /srv/htdocs/sites/test
<Directory "/srv/htdocs/sites/test">
AllowOverride All
Options All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Also, at the top of your public/index.php check that $_GET['_url'] has the URI passed to your browser

Related

Error 403 on yii2 backend

The yii2-advanced template is used. After the transfer to production (using CentOS) on the files of scripts and styles I catch the error 403 That is, the page is given, and the styles are not tightened.
And if you go through a direct link (according to styles), then they are given correctly (response 200). What could be the reason?
Conf for backend
<VirtualHost *:443>
ServerName cp.tickets.site.ru
ServerAdmin osd#site.ru
DocumentRoot "/var/www/vhost/tickets.site.ru/htdocs/backend/web"
Options FollowSymLinks
DirectoryIndex index.php index.html
RewriteEngine on
<Directory "/var/www/vhost/tickets.site.ru/htdocs/backend/web">
RewriteEngine on
AllowOverride none
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.php
RewriteRule ^ index.php [L]
</Directory>
ErrorLog /var/www/vhost/tickets.site.ru/logs/cp_http_error.log
TransferLog /var/www/vhost/tickets.site.ru/logs/cp_http_access.log
</VirtualHost>

.htaccess file mod_rewrite redirecting to parent directory instead of sub-directory when file names are same in both directories

I am accessing the root directory via domain-A.com and a sub-directory via domain-B.com
All redirects are working properly for domain-B.com except those that are having same names for instance if root directory contains a file called abc.html and subdirectory also contains the file abc.html in that case accessing domain-B.com/abc.html shows the contents of domain-A.com/abc.html but the url remains the same i.e. domain-B.com/abc.html
I would like to know how can this be resolved.
I am using Ubuntu and these are the settings that I have made for various file
I have already enabled mod_rewrite using sudo a2enmod rewrite
.htaccess -
path /var/www/html
# Do not change this line.
RewriteEngine on
# Change domain.com to be your primary main domain. http://domain-b.com/
RewriteCond %{HTTP_HOST} ^(www.)?domain-b.com$
# Change 'subfolder' to be the folder you want to redirect request to.
RewriteCond %{REQUEST_URI} !^/domain-b/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you want to use for your primary domain.
RewriteRule ^(.*)$ /domain-b/$1 [L]
# Change domain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain-b.com$
RewriteRule ^(/)?$ domain-b/index.html [L]
httpd.conf -
Path /etc/apache2/conf-available
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
000-default.conf -
Path /etc/apache2/sites-available
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
000-default.conf -
Path /etc/apache2/sites-enabled
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Issue is with these 2 conditions:
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Which means if a file or directory exists in site root dir then don't rewrite to sub-directory.
Just change your rule to this:
RewriteEngine on
# Change domain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www\.)?domain-b\.com$ [NC]
RewriteRule ^/?$ domain-b/index.html [L]
# Change domain.com to be your primary main domain. http://domain-b.com/
RewriteCond %{HTTP_HOST} ^(www\.)?domain-b\.com$ [NC]
# Change 'subfolder' to be the folder you want to redirect request to.
RewriteCond %{REQUEST_URI} !^/domain-b/ [NC]
# Change 'subfolder' to be the folder you want to use for your primary domain.
RewriteRule ^(.*)$ /domain-b/$1 [L]

Redirect with htaccess on apache

I am trying to create a virtualhost and allow a htaccess to redirect (it is for a laravel project).
I am my environment is: ubuntu16.04 apache2.4.18 php7.0.4
And here is my /etc/apache2/sites-available/sub.domain.com.conf
<VirtualHost *:80>
ServerName eatec.es
ServerAlias webs.eatec.es
ServerAdmin eloy#eatec.es
DocumentRoot /var/www/html/sub.domain.com/public
<Directory "/var/html/sub.domain.com/public">
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
#ErrorLog ${APACHE_LOG_DIR}/error.log
#CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Things that I tried (and remember).
1. The line of Directory I tried removing the quotes.
2. The line of Directory I used too this (removing the subdomain sub -with and without the quotes-).
3. I move the Directory block from this file to /etc/apache2/apache2.conf (I paste the last of this type of blocks).
4. I change the AllowOverride option on the block (on the apache2.conf -with my Directory block in apache.conf but too on sub.domain.com.conf-).
5. There was more micro changes, sure... but I don´t remember.
One more thing I tried was a2enmod rewrite but it doesn´t work (though I see mod_rewrite on the loaded modules if I make a phpinfo()).
This is my .htaccess content:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
It is the default htaccess file on a laravel project. It is supposed to redirect the index.php on the same folder. My folder structure is the next:
/var/www/html/sub.domain.com-------------> All The Project
/var/www/html/sub.domain.com/public---> htaccess and index.php
Any suggestion?? Thanks.

Apache: difference virtualhost and htaccess

I set up a private server (raspberry) with apache.
the config file for the website:
<VirtualHost *:80>
ServerName me.example.com
ServerAlias me.example.com
RewriteEngine On
#only rewrite if not one of the followed files is requested
RewriteCond %{REQUEST_URI} !^/images/.*\.(jpg|ico|png|mp4|ogg)
RewriteCond %{REQUEST_URI} !^/css/.*\.css
RewriteCond %{REQUEST_URI} !^/js/.*\.js
#rewrite all requests to index.php and get path (only intern)
RewriteRule ^/([^/]*)/(.*)$ /index.php?lang=$1&path=$2 [NC]
DocumentRoot /var/www/my/root
<Directory /var/www/my/root>
Options FollowSymLinks
Options -Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
1.) If I request now a "subpage" like /impressum.php. It will show me the impressum, instead of rewriting to the index file. Why?
2.) Now I copied the part of the rewrite engine into a .htaccess file and it doesn't work anymore. Where is the difference between these two files? What do I need to change, so it will work?
My .htaccess file looks like:
Options +FollowSymLinks
RewriteEngine On
#only rewrite if not one of the followed files is requested
RewriteCond %{REQUEST_URI} !^/images/.*\.(jpg|ico|png|mp4|ogg)
RewriteCond %{REQUEST_URI} !^/css/.*\.css
RewriteCond %{REQUEST_URI} !^/js/.*\.js
#rewrite all requests to index.php and get path (only intern)
RewriteRule ^/([^/]*)/(.*)$ /index.php?lang=$1&path=$2 [NC,L,QSA]
Thanks in advance
the files were missing ... so it redirected to the home.
It works better then me

DocumentRoot must be a directory CentOS6.5

I've been having a problem setting a directory in my virtualhosts, and am wondering if you guys can help. This is for Laravel and I have already made sure that the location exists and SELinux is disabled.
My config is as follows:
http://i.gyazo.com/31cdec5f9d830ec43923b4ccf1588d4c.png
I can't paste it here because the symbols mess up the formatting.
You should change your document root to:
/var/www/QuickPush/public
See the following virtualhost configuration I always use under CentOS 6:
<VirtualHost *:80>
ServerName quickpush.jackryder.co.uk
DocumentRoot /var/www/QuickPush/public
<Directory /var/www/QuickPush/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>