Wordpress “Post name” permalinks not working - wordpress

I have a Wordpress website running on Lamp Server on Ubuntu Server 14.04.
I just tried to use the option for Post Name permalinks, and now my pages no longer load up.
I turned on the mod_rewrite function of the Apache server, restarted it, but it still doesn't work.
Also, here's my .htaccess file:
# 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
Note that the content of /wordpress folder has been put directly inside /html
Let's say the name of my website is mywebsite.com.
How can I make it work?
EDIT: Here is my /etc/apache2/sites-available/000-default.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 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

I found a fix. So happy!
In short, the fix for me was to go into the WordPress admin dashboard, go to:
“Settings” > “Permalinks” > “Common settings”, and set the radio button to “Custom Structure”
, and paste into the text box:
/index.php/%year%/%monthnum%/%day%/%postname%/
, and click the Save button

have you enabled the use of .htaccess like described here ?
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles

For those running apache 2.4 and not finding "default" look in /etc/apache2/apache2.conf and edit
Directory
AllowOverride All
Directory
Directory /var/www/>
AllowOverride All
Directory

edit .ht_access
insert this line in IfModule mod_rewrite.c
RewriteRule ^(.*)$ index.php?_REQUEST=$1 [L]
IT work for me.

Related

httpd.conf for drupal deployment

I am trying to create a multi drupal site in one server. I have placed my drupal like
/var/www/html/drupal
/var/www/html/drupal01
/var/www/html/drupal02
I cant use subdomains for this appIication and i would like to access each drupal site like http://www.example.com (/var/www/html/drupal) , http://www.example.com/drupal01 (/var/www/html/drupal01)
I am able to configure my first drupal instance ie http://www.example.com. How can I try access my other drupal instances.
<Directory "/var/www/html/rdsadminhelp/">
RewriteEngine On
RewriteBase /
AllowOverride None
Require all granted
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
What you are looking for is VirtualHosts
# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example2.com
# Other directives here
</VirtualHost>
https://httpd.apache.org/docs/2.4/vhosts/examples.html
The default root path of apache server in ubuntu for the domain name 'localhost' is pointed to the /var/www/html folder, that's how you can access the /var/www/html/your_project via http://localhost/your_project.
You can actually create a virtual host with a domain name of your preference (eg: your_domain) for your project folder (eg: /home/user/projects/your_project) so that you could access the project by visting the local url http://your_domain. This would require adding your domain name to /etc/hosts file and placing and enabling the virtual host configuration file which contains the domain name and the project directory path. More details: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
I have created a bash script to do this step very easily. You just
need to execute the script enter the domain name & project path and it
will create the virtual host for you.
bash script: https://github.com/sudheeshsbabu/VirtualHost
Steps to create virtualhost using the bash script: https://www.zyxware.com/articles/5742/virtual-host-creation-using-bash-script

Error 404 post name permalink wordpress

I have just migrated my WordPress site from a Windows to a Linux server. Everything seems to work except the posts with the permalinks set to /%postname%/. I assumed this was mod_overwrite issue.
I have changed the httpconf file from AllowOverride None to AllowOverride All
And then reset the server just to make sure it took effect.
My .htaccess looks like this:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I'm running Apache 2.2 on CentOS5 on a dedicated server.
To add: all the pages are working except the posts with these custom permalinks.
I have set permission to 666 for the .htaccess
The same happened with me too. It turned out that .htaccess was not the issue for me. The issue was in server configuration file.
For AWS EC2 server:
Step 1: Edit configuration file
sudo nano /etc/httpd/conf/httpd.conf
Edit this file and change
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.
Step 2: Restart server
Please don't forget to restart your server after you do the changes to the .conf file.
sudo service httpd restart
For Ubuntu server:
Step 1: Edit configuration file
sudo gedit /etc/apache2/apache2.conf
Edit this file and change
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.
Step 2: Restart server
Please don't forget to restart your server after you do the changes to the .conf file.
sudo service apache2 restart
Keep AllowOverride none.
Remove the .htaccess file and any trace of that messy set of rewrite rules and just add this in virtualhost:
FallbackResource /index.php
Neither mod_rewrite, neither .htaccess are needed.
By adding per-dir configurations you are basically complicating your life. Everything will be much harder to do, for what? to have dynamic changes by changing a file? .htaccess is meant for non-admin users who need to modify directory configurations.
Since you are the admin, configure everything possible in Virtualhost instead.
Giving rw permissions to everyone to files is definetly not the way to go either. httpd does not need write access to anything.

Subdomain always redirect to WWW (home page)

I want, when open subdomain to return existing Wordpress page ex. www.example.com/custom-wordpress-page.
Server OS is CentOS 6.6, while Web Server (httpd) is Apache 2.2.15.
It have installed and configured Wordpress with .htaccess files configured for it's mod_rewrite.
Root folder is /var/www/html.
.htaccess file is in /var/www/html/.htaccess :
# 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
This configuration is working very well with one domain (ex. example.com). Today I wanted to add subdomain (ex. subdomain.example.com).
I tried multiple solutions including VirtualHosts with/without NameVirtualHost in httpd.conf file, also adding RewrriteCond&RewriteRule
under mod_rewrite in .htaccess file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin email-address-redacted
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email-address-redacted
ServerName subdomain.example.com
ServerAlias subdomain.example.com
Redirect permanent / http://example.com/custom-wordpress-page
</VirtualHost>
Also in first VirtualHost, I tried *.example.com instead off www.example.com.
In second one, I tried to make Reverse Proxy using ProxyPass and ProxyPassReverse.
Instead of using :*80 I tried using IP address of server and domain name.
Using .htaccess Rewrite rule with/without VirtualHosts gave no results.
subdomain.example.com always opens www.example.com instead of www.example.com/custom-wordpress-page.
Keep in mind - there is a lot of threads like this, but I tried many of them, including many tutorials but they aren't working alongside Wordpress.
Edit : Want to add that there are no wildcards in DNS records. There are NS records, one A record for example.com, one A record for subdomain.example.com and CNAME record for www that is poiting to example.com. There are NO *.
There was problem with hosting provider DNS records, configuration was correct, but I had to call provider to check records in their system and fix what is broken. After they done their job, it works correctly.

Links not working in Wordpress 4.1

I have Wordpress 4.1 application on DigitalOcean.
After installation I found that any other link besides root/home link don't work.
I looked into similair questions and tried:
1) Change permalinks to default settings.
Now links partialy work. I mean they are ugly :http://104.131.95.146/?post_type=product instead of http://104.131.95.146/products
As suggested I did some troubleshooting from this link :
Pretty permalinks are available under:
Apache web server with the mod_rewrite module
But my server is Apache and I checked if mod_rewrite is aviable with:
apache2ctl -M | grep rewrite
got this message :
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
rewrite_module (shared)
Tried to restart apache and my droplet but still the same problem.
My htacces file inside var/www/html/.htaccess
# 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
Any help would be great.
Thanks in advance.
Once again fixed by myself.
I skipped important part of Wordpress installation.
What I did:
By default, this is 000-default.conf, but your file might be different if you created another configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Inside of this file, we want to set up a few things. We should set the ServerName and create a directory section where we allow overrides. This should look something like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName server_domain_name_or_IP
<Directory /var/www/html/>
AllowOverride All
</Directory>
. . .
When you are finished, save and close the file.
Next, we need to enable the rewrite module, which allows you to modify URLs. You can do this by typing:
sudo a2enmod rewrite
After you have made these changes, restart Apache:
sudo service apache2 restart

Remove web / app.php of reference. Symfony2

All requests go through the file web / app.php (similar to index.php), such as a request to the main page - adwords-up.com/web/app.php, input - adwords-up.com /web/app.php/login. I want part of the web / app.php removed from the link. In the configuration .htaccess, redirect to the default web / app.php, so that a request for such was the main form - http://adwords-up.com/, and Page login - http://adwords-up.com/login.
There is my /etc/apache2/sites-available/adwords-up.conf
<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 adwords-up
ServerAdmin webmaster#localhost
DocumentRoot /var/www/adwords-up/web
# 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>
this might help you
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the startpage because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
</IfModule>
add this to your .htaccess and be sure to have rewriteEngine activated
also this is a common question with answers even on the symfon2 doc
You need to set up apache virtual host and put the correct document root and rewrite rules.
example:
<VirtualHost *:80>
ServerName adwords-up.com
DocumentRoot <path-to-your-codebase>/web
DirectoryIndex app.php
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
RewriteEngine on
RewriteOptions Inherit
RewriteRule ^/app.php/(.*) http://adwords-up.com/$1
RewriteRule ^/(.*) /app.php/$1 [QSA,L]
<Directory "<path-to-your-codebase>/web">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Hope it helps

Resources