domain redirect working sporadically - php

When I go to my site's domain, it redirects to the WWW subdomain, which isn't what I want. It also just takes me to the domain registrar's like "page coming" page.
I did a CNAME change for the DNS of my domain, I set up a wordpress, I made a file in /etc/apache2/sites-available/ that looked like
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# 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
ServerName $MYSERVERNAME.tld
ServerAlias www.$MYSERVERNAME.tld
ServerAdmin $MYEMAILADDRESS
DocumentRoot /var/www/html
<Directory /var/www/html/>
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>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
my .htaccess file (which should redirect www to non-www):
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
i can provide more info including the domain if necessary

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.

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.

Why does Apache print the contents of my PHP files instead of passing them to PHP-FPM?

I have the below configuration file under sites-enabled. I'm using mod_proxy_fcgi.
ServerName local.dev
<Directory /var/www/local/>
AllowOverride all
Require all granted
</Directory>
<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.
ServerAlias *.local.*.com
SetEnv CURRENT_ENVIRONMENT ENV_DOCKER
ServerAdmin webmaster#localhost
VirtualDocumentRoot /var/www/local/%3/trunk/%3+-%1/site/www
ProxyPassMatch "^/var/www/local/(.*/trunk/.*/site/www/.*\.php.*)$" "fcgi://php:9000/var/www/local/$1"
# 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 debug
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
<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.
ServerAlias local.*.com
SetEnv CURRENT_ENVIRONMENT ENV_DOCKER
ServerAdmin webmaster#localhost
VirtualDocumentRoot /var/www/local/%2/trunk/%2+/site/www
ProxyPassMatch "^/var/www/local/(.*/trunk/.*/site/www/.*\.php.*)$" "fcgi://php:9000/var/www/local/$1"
# 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 debug
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
It turned out that I just needed a SetHandler directive in my Apache config.
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://php:9000"
</FilesMatch>

Apache2.4 ReWrite

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.

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