How configure .htaccess, vhost, hosts to use Zend_Controller_Router_Route_Hostname? - php

I read about Zend_Controller_Router_Route_Hostname, but i havent idea how.
i try to use it, zend documentation. But when i try to open someoneusername.localhost/ my browser dont found nothing.( Oops! Google Chrome could not find ... ).
i verified my .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
and vhost config
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName localhost
DocumentRoot "/var/www/zendtest/public"
<Directory "/var/www/zendtest/public">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error-localhost.log
CustomLog ${APACHE_LOG_DIR}/access-localhost.log combined
</VirtualHost>
hosts file
127.0.0.1 localhost
please someone help me.

Assuming everything else has been configured correctly, you'll want to change your VirtualHost Directive:
ServerName localhost
to
ServerName localhost
ServerAlias *.localhost
and then restart apache.
I'm afraid you're out of luck with the hosts file (wildcards unsupported)
See the link for alternatives.

Related

Error 404 being given on a virtaul host with custom .htaccess file

I have an apache2 installation on my local linux server. It has a virtual host called pcts.local which has the root /var/www/repos/pcts/. Inside the root of pcts.local is a .htaccess file which attempts to rewrite urls to include .php if it isn't given like below:
http://pcts.local/ -> http://pcts.local/index.php
http://pcts.local/contact -> http://pcts.local/contact.php
The problem is, http://pcts.local/contact gives an error 404 but http://pcts.local/contact.php gives 200.
Virtual Host Configuration:
<VirtualHost *:80>
ServerName pcts.local
ServerAdmin webmaster#localhost
DocumentRoot /var/www/repos/pcts
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess file in /var/www/repos/pcts/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [NC,L]
Thanks in advance of any help!
<VirtualHost *:80>
ServerName pcts.local
ServerAdmin webmaster#localhost
DocumentRoot /var/www/repos/pcts
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If this is your complete config then your .htaccess file is not being processed.
You've not enabled .htaccess overrides for the specific directory. (ie. You've not enabled the parsing of .htaccess files.) .htaccess overrides are disabled by default.
However, you've not enabled access to this area of the filesystem either? Have you done this elsewhere in the server config?!
You should have a relevant <Directory> section like the following inside the <VirtualHost> container:
<Directory /var/www/repos/pcts>
# Enable .htaccess overrides
AllowOverride All
# Allow user access to this directory
Require all granted
</Directory>
You can restrict .htaccess overrides further if required (see the reference link below)
Reference:
https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
In your code, REQUEST_FILENAME is expecting a file with a php extension to perform the rewrite.
Try this instead:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Configuring Symfony 5 Application on Apache server

I need some help with configuring Symfony on apache2 web server.
My current project category structure is:
var/www/domain.com/public_html
Inside public_html is where my Symfony application is located.
I am stuck at figuring our what I am doing wrong in my either .htaccess or /etc/apache2/sites-available/domain.com.conf files.
I am using symfony/apache-pack. My .htaccess files live inside /public folder as per documentation. Here it is:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
And here is my /etc/apache2/sites-available/domain.com.conf
<VirtualHost *:80>
ServerAdmin someemail#example.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/mydomain.com/public_html/public>
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I also read this and updated 000-default.conf as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/domain.com/public_html/public>
Options FollowSymlinks MultiViews
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
</IfModule>
</VirtualHost>
For the moment I am still seeing symfony project folder structure.
I tried:
inside .htaccess changing DirectoryIndex to /public/index.php
inside .conf file changin DocumentRoot to /va/www/domain.com/public_html/public
tried clearing cache
SO far nothings seems to help.
Would be extremely helpful for any advice.
I see that you are editing vhost which begins with
<VirtualHost *:80>......
That mean your website should be reachable by 80 port or in other words by http protocol. But! If in reality you are accessing your website by https protocol then make sure you are editing right Apache2 .conf file.
If the website is reachable by https protocol (especially if you use LetEncrypt), then try locating /etc/apache2/sites-available/....-le-ssl.conf config file (or similar one with corresponding domain title and with ssl prefix or postfix in it's name).
After editing that file do not forget to restart Apache2 webserver with $sudo service apache2 restart and test website again.

setting .htaccess file in slim

I am having issues redirecting to index.php in my slim app with .htaccess file.
Routes work if I add the index.php at the end of the URL
So slimapp.dev/hello/myname gets error
Not Found The requested URL /hello/myname was not found on this server.
while slimapp.dev/index.php/hello/myname works
Here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php [QSA,L]
I am using Apache 2 on Ubuntu 18.04
File structure
public_html
|_index.php
|_ vendor
|_.htaccess
virtualHost 000-default.conf
<VirtualHost *:80>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If I use the php -S localhost:3000 it works as expected but if I use the Apache web server, I most add the index.php to the end of the URL to make it work. Thanks
You are doing wrong.This is quite simple with just two lines of code:
RewriteEngine On
RewriteRule ^myname/(.*)$ /$1 [L]

Running Angular 2 on Ubuntu Server - Blank Screen No Errors

I have an angular 2 project, when I run on my locally via XAMPP it works fine, but when I add Angular 2 to my Ubuntu Server, I get a blank white screen with no errors. I add an .htaccess file and it looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
I also enabled Apache's mod_rewrite extension and adjusted my VirtualHosts in /etc/apache2/sites-available/laravel.conf file so it looks like this:
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/front/src
<Directory /var/www/html/front>
AllowOverride All
</Directory>
Alias /api /var/www/html/api/public
<Directory /var/www/html/api>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
But all I get is a blank screen with no errors on the page.
I am running Angular CLI: 1.6.2, node v8.11.3, npm 6.3.0
PLEASE HELP!

Remove .php extension in .htaccess not working

I have a test website on my ubuntu computer, the URL is: mysite.test. I have marketing pages: http://mysite.test/hello.php, http://mysite.test/goodbye.php, etc.
I also have wildcard subdomains: http://user1.mysite.test/page1.php, http://user2.mysite.test/page.1php, etc.
I'd like all pages to be accessible without adding the ".php" extension (marketing site, and subdomains). I've modified my .htaccess files, but its not working and I can't figure out why. mod_rewrite is enabled and working (the "Remove www" rule below works).
#/var/www/mysite.test/public_html/.htaccess
RewriteEngine On
#Remove www - this works
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC]
#Not need .php extension - this does not work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php
Removing the first rule ("Remove www") doesn't make it start working.
When I go to http://mysite.test/hello I get a 404 Not Found error. Going to http://mysite.test/hello.php loads just fine.
When I go to http://user1.mysite.test/page1 I get a 404 Not Found error. Going to http://user1.mysite.test/page1.php loads just fine.
My Virtual Hosts file looks like this:
#/etc/apache2/sites-available/mysite.test.conf
<VirtualHost *:80>
ServerName www.mysite.test
ServerAlias mysite.test
ServerAdmin fake#gmail.com
DocumentRoot /var/www/mysite.test/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/mysite.test>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName wildcard.mysite.test
ServerAlias *.mysite.test
DocumentRoot /var/www/mysite.test/public_html/app
<Directory /var/www/mysite.test/public_html/app>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
What am I missing? Thank you.
I'm not sure I can give you a helpful solution to your issue, but I have a similar piece of code that works:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.|/]+)$ $1.php [NC,L]
this sets that if it is not a file, and if it doesn't contain a . (such as an image reference.jpg then it has .php appended to the filename.
This works perfectly for me.

Categories