My server was recently compromised. I moved everything to a new server, but for some reason the permalinks for the Wordpress site are not working properly. I've looked everything over and it all appears to be correct, but I can't see why the links won't work when the settings were all copied over from the old server where they all worked.
Server .conf:
<VirtualHost *:80>
ServerName www.XXX.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/XXX.com/
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>
<VirtualHost *:80>
ServerAlias XXX.com
ServerAdmin XXX
DocumentRoot /var/www/html/XXX.com/
ServerName www.XXX.com
DirectoryIndex index.html index.php
<Directory "/var/www/html/www.XXX.com/">
allow from all
Options -Indexes
AllowOverride All
</Directory>
CustomLog ${APACHELOGDIR}/XXX.log common
ErrorLog ${APACHELOGDIR}/XXX-error.log
</VirtualHost>
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUESTFILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Make sure .htaccess has right permissions so that wordpress can change it on its own.
Related
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]
This is my Virtual Host:
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host.localhost:8080
DocumentRoot "D:/test/testpage/"
ServerName testpage
ServerAlias testpage.localhost
ErrorLog "logs/testpage-error.log"
CustomLog "logs/testpage-access.log" common
</VirtualHost>
system/host
127.0.0.1 testpage.localhost
httpd.conf in xampp/apache/conf/
Listen 8080
ServerName localhost:8080
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
AllowOverride All
Require all granted
</Directory>
my .htaccess file inside testpage folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and in my application/config/config.php
$config['base_url'] = 'http://testpage.localhost:8080';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
the only issue am facing is that index.php, i can access my other pages but it have index.php between base_url() and view.
I suggest trying the following VirtualHost (vhost) directives.
It defines D:/test/testpage/testpage as the pubic root of the site. Both .htaccess and CodeIgniter's index.php should be in this directory.
I've removed the ServerAlias - you don't need it.
I've added explicit directives for the vhost directory
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host.localhost:8080
DocumentRoot D:/test/testpage
ServerName testpage
ErrorLog "logs/testpage-error.log"
CustomLog "logs/testpage-access.log" common
<Directory D:/test/testpage>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
system/host should be
127.0.0.1 testpage
Because you have named the virtual host "testpage" the following should work.
$config['base_url'] = 'http://testpage/';
I want to configure a Wordpress application with a simple php application. The directory structure of the application is as follow :
Root directory : /var/www/demoApp/
Wordpress directory : /var/www/demoApp/wordpress/
Here i want to access the wordpress application using route http://BASE_URL/wordpress. But i am not able to configure the htaccess file. All the php pages under /var/www/demoApp/ directory are working fine using url http://BASE_URL/. While wordpress files are not being loaded correctly.
Here is my Apache configuration block :
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www/demoApp
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/demoApp>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What should be the .htaccess file?
My configuration:
domain: test.localhost
wordpress url: test.localhost/wordpress
.htaccess in the wordpress folder:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Apache settings for the subdomain (Wamp server under windows)
<VirtualHost *:80>
DocumentRoot "e:\Sync\www\test"
ServerName localhost
ServerAlias test.localhost
<Directory "e:\Sync\www\test">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
</Directory>
</VirtualHost>
I had this issue while trying to modify a few absolute paths to relative paths. The problem was that I left an extra / at the start of the relative path.
Correct Code:
About
<!--The link goes to to http://BASE_URL/wordpress_subdirectory/about-->
Errorneous code:
/About
<!--This href is relative to the 'Root'. It goes to http://BASE_URL/about-->
I'm using Ubuntu 14.04. I have installed LAMP, Composer and I installed Laravel. I created virtual domain (laravel.dev) and it works, but only when I'm using for simple laravel.dev/index.php/auth/login. When I use laravel.dev/css I have laravel/public/css folder. I have default .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
AllowOverride All
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And my *.conf file:
<VirtualHost *:80>
ServerName laravel.dev
ServerAdmin webmaster#laravel.dev
DocumentRoot /var/www/laravel/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
How can I fix it?
My main page:
http://i.imgur.com/AxQjV9q.png
I fall this problem.I solved it using apache mod rewrite enable.For that follow this
http://www.kingpabel.com/apache-mod_rewrite/
Currently, your virtualhost doesn't allow overriding the rewriting settings in the .htaccess of your project.
You should add the following lines to your .conf file, in the virtualhost :
<Directory "/var/www/laravel/public">
AllowOverride All
</Directory>
Which would result in the following file :
<VirtualHost *:80>
ServerName laravel.dev
ServerAdmin webmaster#laravel.dev
DocumentRoot /var/www/laravel/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/laravel/public">
AllowOverride All
</Directory>
</VirtualHost>
I need to access a web app via below URL:
https://www.localhost/index.php
Below is my Apache configuration:
ScriptAlias /www.localhost/ "/var/www/siva/scripts/"
Alias /pages/ "/var/www/siva/wpages/"
ServerName www.localhost
<Directory "/var/www/siva/scripts">
AllowOverride None
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Options None
</Directory>
<Directory "/var/www/siva/wpages">
AllowOverride None
Options None
</Directory>
/var/www/siva/scripts/index.php
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
If I access my page in a browser as URL:
http://localhost/www.localhost/index.php
it works fine but the same does not if I access as
http://www.localhost/index.php
What changes should I make to achieve the same and how can I make it available at "https" protocol only?
Prakash, you need to add ServerAlias to make it work as localhost as well, and add HTTPS redirect, RewriteRule, as I understood, it's what you want, for example:
ScriptAlias /www.localhost/ "/var/www/siva/scripts/"
Alias /pages/ "/var/www/siva/wpages/"
ServerName www.localhost
ServerAlias localhost
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
httpd ServerAlias Directive:
The ServerAlias directive sets the alternate names for a host, for use with name-based virtual hosts. The ServerAlias may include wildcards, if appropriate.
EDIT 1:
At first, after you edit httpd's .conf files restart your httpd, e.g: service httpd restart. You can create VirtualHost to workaround your problem:
<VirtualHost 127.0.0.1:80>
ServerName localhost
ServerAlias www.localhost
DocumentRoot /path/to/your/site/root
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
Then do the same for SSL site:
<VirtualHost 127.0.0.1:443>
ServerName localhost
ServerAlias www.localhost
DocumentRoot /home/localhost #path to your localhost root directory
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] #rewrite all www to non-www
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
SSLEngine on
SSLCertificateFile /home/localhost/ssl.cert
SSLCertificateKeyFile /home/localhost/ssl.key
SSLCertificateChainFile /home/localhost/ssl.bundle
</VirtualHost>
EDIT 2:
For SSL site you can change /etc/httpd/conf.d/ssl.conf (it could depend on your Linux distribution) but at the same time, there is no real need for that and you could just place your directives in httpd.conf.