Apache2.4 ReWrite - php

I have a UCP for my SAMP server, what worked fine with Apache2.2, but now we would like to move onto Ubuntu 14.04 with latest version of PHP and Apache.
But since sites-available using new method (.conf sites) somewhy our UCP not works.
Website: http://ucp.classrpg.net/
Problem, when you click to any link its redirect to a php file, which has been rewrited to .web file in .htaccess file.
RewriteEngine on
# anything that contains a dot without a colon should be left alone
#RewriteRule ^[^:]*\. - [L]
# anything that contains a slash without a colon should be left alone
#RewriteRule ^[^:]*\/ - [L]
# redirect to main page
#RewriteRule ^/*$ /fooldal.php [L,QSA]
# anything else is to be treated as a title
#RewriteRule ^(.+)$ /data/$1 [L,QSA]
RewriteRule (.+).see(\?[.+?])?$ $1.php$2
RewriteRule (.+).web(\?[.+?])?$ $1.php$2
RewriteCond %{HTTP_HOST} ^(www\.)?kliens\.
RewriteRule (.*) http://ucp.classrpg.net/kliens.web [L]
AddDefaultCharset utf-8
#php_value display_errors 1
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value memory_limit 15M
AddType application/exe .lnk
Options -Indexes
ErrorDocument 404 /404.php
IndexIgnore *
<Files 403.shtml>
order allow,deny
allow from all
</Files>
<filesmatch "\.ori">
deny from all
</filesmatch>
Allow from 127.0.0.1
Allow from ::1
deny from 89.132.170.28
deny from 84.2.181.10
deny from 84.3.218.168
deny from 85.67.242.26
My ucp.conf file:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName ucp.classrpg.net
ServerAdmin sqpp15#gmail.com
DocumentRoot /var/www/usercp
ReWriteEngine On
<Directory /var/www/usercp/>
Options All
AllowOverride None
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

It's not working because you don't have the use of .htaccess file enabled in your ucp.conf file.
This
AllowOverride None
Needs to be changed to this
AllowOverride All
After the change restart apache. Let me know how you come out.

Related

Make my php server a symfony server

I'm trying to make my php server a Symfony server.
I've installed Symfony and I've created a project in /var/www/project_name
If i make server:run my_local_ip:8000 the server run correctly and I can reach it also from a computer on another net with: http://public_ip:8000, instead, if I write http://public_ip it goes on my index.php.
Well, now, I'ld like that if I write http://public_ip it goes on http://public_ip:8000 or atleast if could make Symfony run on port 80 or make Symfony run on php built-in server.
I've tried to create a virtual host, I've created this file:
project_name.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName project_name
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
DocumentRoot /var/www/project_name
<Directory /var/www/project_name>
Options Indexes FollowSymlinks Multiviews
AllowOverride All
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
But it doesn't work and if I write http://public_ip it runs always my index.php.
Can you give me an help?
Completed Solution - Thanks to #Alberto Fecchi answer:
Edit 00-default.conf
Paste what you found on Alberto Fecchi's answer and also add this
#IT NEEDS "<" BEFORE TAG
Directory /var/www/tcgfiga/web/bundles>
IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
/Directory>
Then make "sudo service apache2 restart". Sometimes it is necessary, sometimes not
Go into folder "/var/www/project/web/" and search ".htaccess" file
You should delete it, but if so your application doesn't run and you see and page with the content of the folder, recreate it and open it. You have to search
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Comment the line RedirectMatch 302 ^/$ /app.php/
Now it works :)
Use this Virtual Host:
<VirtualHost *:80>
ServerName project_name
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
DocumentRoot /var/www/project_name/web
<Directory /var/www/project_name/web>
Options Indexes FollowSymlinks Multiviews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable it with sudo a2ensite project_name and restart with sudo service apache2 restart (commands could be different on various OS).
Now you can visit http://public_ip to see your "production" application.

pretty url not working on laravel5.2

It seems that pretty URLs are not working for me. I have tried every thing I know, when you try http://wasamar.com.ng/login it gives a response of 404 Not Found but http://wasamar.com.ng/inde.php/login is ok, I have edited my public/ directory's .htaccess file to this:
<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]
</IfModule>
This is the /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName wasamar.com.ng
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/wasamar/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
What am I doing wrong?
It's probably because your apache rewrite module is not enabled. To enable the rewrite module on a Ubuntu machine:
sudo a2enmod rewrite
sudo service apache2 restart
If a2enmod is not available on your platform, you need to open up your httpd.conf file and uncomment the line including rewrite_module. That's something like this on a macOS machine:
LoadModule rewrite_module libexec/mod_rewrite.so
Then you need to restart the service.
Also, for htaccess files to be effective you need to set AllowOverride directive to All. Here's an example:
<Directory "/absolute/path/to/webserver/root">
# ...
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
# ...
</Directory>
thanks everyone for the support but i saw my error, in the /etc/apache2/apache2.conf file i did not add the AllowOverride All section the dirctory tags, when i fixed that it worked.

.htaccess doesn't work in apache

I have the following problem:
I want to remove .php and .html extention from url of my website.
The URL is localhost/MySiteDir/MySitePage.php and I want to obtain localhost/MySiteDir/MySitePage.
I am following this:
https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
& this
How to remove file extension from website address? guides.
So I created a .htaccess file on my MySiteDir and I put this code on this file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
But it doesn't work.
I have changed etc/apache2/sites-enabled/000-default.conf file adding
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
in this way:
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
and in my .htaccess file I put:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
when I try to access my website I receive a 404 Error.

Wordpress is refusing to load

I've been trying to install a wordpress blog on an apache virtualhost for several days now to no avail. Note, the virtual host configuration works just fine, as each virtual host loads up its respective index.html or index.php. Only on a Wordpress install do I get no response. My conf file looks like
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin#example.com
DocumentRoot /var/www/example
<Directory /var/www/example/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
The blog is located in directory /var/www/example and my .htaccess file looks like
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have mod_rewrite enabled, so I'm not sure what the issue is. Checking the apache error log turns up nothing and the access logs always show a return of 301. Any ideas?
I fixed this by deleting the .htaccess in the /var/www/example directory and removing the lines in the conf file.

codeiginiter always shows 404 error ubuntu 14.04

I done a project using codeiginiter in windows(XAMPP), now i changed my OS to UBUNTU 14.04 and i have installed LAMP and LAMP works fine.
i copied my project files to /var/www/html and changed all the configurations to ububtu
$config['base_url'] = 'http://localhost/lankaproperty/';
$config['index_page'] = 'index.php';
routes
$route['default_controller'] = 'welcome';
$route['404_override'] = 'home/error_404';
$route['500_override'] = 'home/error_500';
$route['translate_uri_dashes'] = FALSE;
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
i have also changed all the file permissions to 755..
when i try the default controller like this
http://localhost/lankaproperty/
it works fine..
but none of the other controller is working
http://localhost/lankaproperty/home
http://localhost/lankaproperty/index.php?/home
i get the error.
`
404 Page Not Found
The page you requested was not found.
`
can someone help me to fix this issue tnx..
etc/apache2/apache2.conf
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
sites-enabled/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
sites-avalible/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Replace the value from these two section in config file.
$config['base_url'] = 'http://localhost/lankaproperty/';
$config['index_page'] = 'index.php';
To
$config['base_url'] = '';
$config['index_page'] = '';
Hope is usefull for u.
Try code from documentation:
//config.php
$config['index_page'] = '';
//.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Categories