Hi guys i am new to Zend framework and today only i have started learning it.so my first step is i am installing ZF1 in my system so i have done the steps which is need for install from below link https://framework.zend.com/manual/1.12/en/learning.quickstart.create-project.html
And when i run http://localhost/quickstart/
it is showing index of those files it is not running index.php file
can any one help me what mistake i have done and i am using the ubuntu server
below are the things which i had followed i had downloaded it downlaoded two zip files one is zendAuth and another one is and zend framework 1.12.20
and i have create one folder names quickstart and and i have moved those files to to inside quickstart.
So now my files are in under the /var/www/quickstart/zendAuth/Zemdframeowrk 1.12.20
And i have made php.ini change in /etc/php/7.2/apache2/php.ini and in that i have made include_path = ".:/var/www/quickstart/zendAuth/library"
and after that in apache2.conf file at the end of file i have added the below code
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerName quickstart.local
DocumentRoot /var/www/html/quickstart/zendAuth/public
SetEnv APPLICATION_ENV "development"
<Directory /var/www/html/quickstart/zendAuth/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And in hosts file at the top of the file i have added this `127.0.0.1 quickstart.local`
Can any one check and let me where i have done mistake and please help me out.
Thanks in advance.
You can try below configuration and then set .htaccess for root and public folder:
1) Entry in hosts file as below
127.0.0.1 quickstart.local
2) Set virtual host in httpd-vhosts.conf as below
<VirtualHost *:80>
ServerName quickstart.local
DocumentRoot "/var/www/html/quickstart/zendAuth/public"
ServerAlias quickstart.local
<Directory "/var/www/html/quickstart/zendAuth/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
3) Check root htaccess as below
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
IndexIgnore *
Options -Indexes
4) Check htacess in public folder as below
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}/index.php [L]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
Related
I have copied the htaccess file from my other sites (that all work, and are on the same server) and have only changed URLs that need changing (ie when redirecting from non-www to www), but it simply does not work.
My changing of, for example, /index.php to /index fails, but /example.html does work at /example, which makes me think it's an issue with PHP or htaccess acting with PHP?
I've asked several friends of mine to have a look at it and they cannot understand why it's happening.
My .htaccess file is:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
And my VirtualHost is:
<VirtualHost *:443>
ServerName example.com
ServerAlias localhost
DocumentRoot "/var/www/example.com/public_html"
<Directory "/var/www/example.com/public_html">
Options +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias localhost
DocumentRoot "/var/www/example.com/public_html"
<Directory "/var/www/example.com/public_html">
Options +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =localhost
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias localhost
DocumentRoot "/var/www/example.com/public_html"
<Directory "/var/www/example.com/public_html">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
ServerAlias localhost
DocumentRoot "/var/www/example.com/public_html"
<Directory "/var/www/example.com/public_html">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =localhost
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
(I've replaced the domain with example.com -- they're not like that in htaccess or the vhost.)
.htaccess is certainly not disabled, if I make a redirect it works just fine, for example:
Redirect 301 /test https://example.com/test
and...
root#server:~# a2enmod rewrite
Module rewrite already enabled
I've never experience any similar issues with my web-server before, and I'm really puzzled as to why the issue is occurring.
You don't actually state what is happening (errors? response codes? etc.), however, there are a few issues with your config with respect to extensionless URLs.
Options +Indexes +Includes +FollowSymLinks +MultiViews
You are explicitly enabling MultiViews in your server config, however, this is going to conflict with the mod_rewrite directives in .htaccess that attempt to append the file extension. MultiViews needs to be disabled. eg. -MultiViews (not +).
However, you are also enabling directory indexes (Indexes) and server-side-includes (Includes) for some reason? Is this intentional? And, rather confusingly, you are setting different options for your www subdomain than for the domain apex?
In the vHost container it is often preferable to state just the options needed. For example:
Options FollowSymLinks
(This naturally disables MultiViews by not setting it.)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
These mod_rewrite directives in .htaccess to append the file extension are not strictly correct. Whilst they may work for your "valid" URLs, a malicious user could construct a URL of the form /index/<anything> that would otherwise map to /index.php, to trigger a rewrite-loop (500 Internal Server Error)*1.
These should be written like this instead (assuming your .htaccess file is in the document root) to avoid this vulnerability:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule (.*) $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule (.*) $1.html [L]
The literal dot does not need to be escaped in the TestString (first argument to the RewriteCond directive) since this is a "string", not a regex. The NC flag is not required here.
If your URLs themselves don't contain "file extensions" then you can optimise the above by not testing URLs that already look like they have a file extension. For example:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule !\.\w{2,4}$ %{REQUEST_URI}.php [L]
The negated regex !\.\w{2,4}$ only matches URLs that don't contain - what looks like - file extensions. A file extension in this context is a sequence of 2 to 4 letters/digits at the end of the URL-path, preceded by a dot.
*1 See my answer to the following ServerFault question that goes into more detail regarding the potential rewrite-loop and resulting 500 error response:
https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error
Hey,
I am trying to make my url a bit prettier with apache mod_rewrite.
html (root)
css
js
layout
sites (folder)
profil.php
work.php
index.php
At the moment my url looks like this:
https://example.com/sites/profil.php
https://example.com/sites/work.php
And I want that it looks like this:
https://example.com/profil
https://example.com/work
How can I can I overwrite the "sites folder" so, there is none and is it possible to remove the .php extension?
Thats how my apache config looks like:
<VirtualHost example.com>
DocumentRoot /var/www/example.com/html
ServerName example.com
ServerAlias www.example.com
<Directory "/var/www/example.com/html">
allow from all
Options None
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Do I need to edit my links after that change in my files?
Here are your mod rewrite rules
# Rewrite --- https://example.com/sites/profil.php => https://example.com/profil
RewriteRule ^profil$ sites/profil\.php [NC,L]
# Rewrite --- https://example.com/sites/work.php => https://example.com/work
RewriteRule ^work$ sites/work\.php [NC,L]
enter this into your .htaccess in the right location and give it a try.
<VirtualHost example.com>
DocumentRoot /var/www/example.com/html
ServerName example.com
ServerAlias www.example.com
<Directory "/var/www/example.com/html">
allow from all
Options None
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteRule ^sites/profil\.php$ /profil?&%{QUERY_STRING}
RewriteRule ^sites/work\.php$ /work?&%{QUERY_STRING}
</VirtualHost>
I set up a local Laravel server for developement and push changes through Git to my production server.
I made a new Laravel project that i pused ok. Then i added php artisan make:auth on my local server and pushed to production but get 404 cant find login (or register). After some work I found out that:
www.mySite.com/login
can not be found but if I write
www.mySite.com/index.php/login it works.
So now I think I have to modify my htaccess to ignore the index.php but I cant get it to work. I tried some suggestions but none seems to work and I don't have a clue why it is not working.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase Test/public/
* RewriteCond %{THE_REQUEST} /index\.php [NC]
* RewriteRule ^(.*?)index\.php$ /$1 [L,R=302, NC, NE]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(.*)/$ /$1 [L,R=301]
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>
The two lines marked with * I tried to add after reading a suggestion here on Stack Overflow (cant find the link now). I also tried
htaccess remove index.php from url
this suggestion.
Any ideas? Thanks.
Edit:
My sites-enabled/000-default.conf looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Test/public
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =nfoscan.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
and my 000-default-le-ssl.conf Looks like this:
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Test/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName mysite.com
</VirtualHost>
</IfModule>
I removed the comments in configs..
I tried to add
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
to my 000-default-le-ssl.conf but it resulted in internal server error..
First check if your apache has enabled mod_rewrite you can do it easily by
typing
apache2 -M
or even simpler:
a2enmod rewrite
if you had enabled it already you will receive message:
"Module rewrite already enabled"
If you haven't then you will receive message:
"Enabling module rewrite". You will have to restart apache.
Check if you have in you htaccess line (AllowOverride All)
<Directory /var/www/html/project/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Ok so I fixed it. There was some problem in my .htaccess file. I started with removing the .htaccess file in /Test/public and then I didnt get internal server error when messing with in 000-Default-le-ssl.conf file anymore. Then I just copied in another .htaccess file in the directory and it all worked as it should :O
Thanks to all who tried to help me!
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
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>
Posting the working .htaccess file if anyone ever have this problem again :)
i have Lumen project working locally that serves as API for my VueJS project, both are in same folder - /var/www/vue-project and /var/www/lumen-api
in my local machine i can start the api using this command: php -S localhost:8000 -t ./public and all my api requests from vue project receive data as responsefrom lumen project.
now i have the same structure on my production server using Apache2 and i cant get this one to work. i have the same structure of files and i started listening with same command but no response from my api.
i added virtual host in my apache config file:
<VirtualHost *:80>
ServerName api.weddiz.co.il
DocumentRoot /var/www/lumen-api
<Directory /var/www/lumen-api>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
but cant manage to generate some response from my api...any idea what am i doing wrong?
your missing /public in your virtualhost file ...
<VirtualHost *:80>
ServerName foo.fo
ServerAlias foo.fo
DocumentRoot /var/www/foo.fo/public_html/lumen-api/public/
ErrorLog /var/www/foo.fo/error.log
CustomLog /var/www/foo.fo/requests.log combined
<Directory /var/www/foo.fo/public_html/lumen-api/public>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
I'm attempting to figure out why it is that my .htaccess file isn't working - I'm assuming that I am somehow configuring my 000-default.conf incorrectly.
000-default.conf
<VirtualHost *:80>
ServerName ****.********.me
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|css|img|js|libs|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
/html is a symlink to /www in my CodeIgniter project. I have removed 'index.php' from $config['index_page'], and the front page of the site loads without any issue. It is when I attempt to access any other page on the site that the issue arises (they will not load unless I add index.php to the beginning of each). I also ran sudo a2enmod rewrite, to no avail. I have also restarted the apache2 service during all of my attempts at fixing the issue. Any ideas?
If you just wanna remove index.php, then here is the steps to follow :
1- set $config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = '';
2- .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]