Links not working in Wordpress 4.1 - wordpress

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

Related

Remove index.php from Wordpress URLs

I am new to Wordpress but tried all documentation and Stack Overflow posts for possible solutions but none of them have worked so far.
I have verified that mod rewrite is enabled and working as expected. Followed all steps mentioned here. https://wordpress.stackexchange.com/questions/105795/remove-index-php-from-permalinks
Also restarted Apache couple of times but still getting 404 errors when I remove index.php path from Permalink Settings.
Renamed the wordpress directory to blog to access the site at www.xyz.com/blog. Now the requirement is to access any blog posts with
www.xyz.com/blog/2018/02/09/my-wp-post without index.php in the URLs.
We don't have any other CMS content other than WP for the blog site.
Permalink settings(Custom Structure):
/index.php/%year%/%monthnum%/%day%/%postname%/
.htaccess file contents:
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I spent ton of time trying many different approaches answered here or elsewhere but none of them fixed my issue.
This is what I did and it has fixed my issue.
Change permalink settings to remove index.php
Update/Save .htaccess content that's at the root of the WP installation if it's not allowed to be updated automatically when we change permalink settings in WP admin panel.
This is the important step since not many Q & A mentioned this in detail, other than wordpress documentation here. Specifically check AllowOverride settings and change it to All, Apache httpd.conf will not load the .htaccess contents without this change. Of course mod_rewrite must be enabled in the server if it's not already done. In our case it's enabled by default, so didn't have to mess with this step.
Also make sure FollowSymLinks option enabled as mentioned in the WP documentation.
Last but not least, make sure you restart the Apache service/server for the changes to take effect.
Entry in httpd.conf file:
<Directory "/var/www/html/blog">
Options FollowSymLinks
AllowOverride All
Assuming Ubuntu 16.04 & Apache2
1) Activate mod_rewrite. It's available but not enabled with a clean Apache 2 installation.
sudo a2enmod rewrite
2) Restart Apache
sudo systemctl restart apache2.service
3) Setup .htaccess
(Note: Apache reccomends using a server configuration file over inserting rules into .htaccess, however, for this example, inserting rules into .htaccess is sufficient because of the negligible performance hit.)
sudo nano /etc/apache2/sites-available/000-default.conf
Insert the following in 000-default.conf
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
4) Restart Apache
Repeat step 2
5) Create .htaccess in the web root.
touch /var/www/html/.htaccess
Insert the following into .htaccess
RewriteEngine On
6 Configure the URL Rewrite (Note: Assuming index.php)
sudo nano /var/www/html/.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
mod_rewrite is a useful Apache module that can be used effectively to ensure human-readable URLs and good SEO results. If you'd like to learn more about mod_rewrite, take a look at Apache's mod_rewrite Introduction and Apache's official documentation for mod_rewrite.
In a nutshell, as #Cnu as mentionned, the problem very few resources on the internet touch on is the fact that your apache configuration must contain an AllowOverride FileInfo directive for wordpress rewrites to work without /index.php/.
Since Apache 2.4, AllowOverride default setting is "None", which is often a roadblock in making "pretty urls" work (in this case ditching the index.php). As #cnu mentionned, you should read carefully this resource : https://wordpress.org/support/article/using-permalinks/.
Make sure to have mod_rewrite enabled
-> (to be sure create an info.php you will remove later containing the line <?php phpinfo();?>) at the root of your blog and call https://domainofyourb.log/info.php)
Make sure your .htaccess is writable by wordpress. (permission and ownership should be allowing your webserver (often with the username "apache") to edit the file.
Change your wordpress permalinks settings, and check that .htaccess file is correctly written.
Check that your apache configuration (etc/httpd/conf/httpd.conf in some linux distros) contains the directive AllowOverride FileInfo within your blog's <Directory></Directory> section
Options directive to FollowSymLinks should be the default, but if Options directive is mentionned, add FollowSymLinks for good measure.
when all that is done, don't forget to restart your Apache server. (sudo service httpd restart in my case, ymmv).
P.S : wrote this answer because I can't comment (don't have rep) on cnu's answer, and wanted to correct 1. allowoverride doesn't need to be set to ALL, it can be set to simply "FileInfo", 2. update the link to wordpress doc, and 3. provide background on the change in apache 2.4 that causes this issue.
Go to admin page, Dashboard -> Settings -> Permalink Settings -> Custom Structure, select /%postname%/ or, /%year%/%monthnum%/%day%/%postname%/ up to you.

Apache 2.4 + FPM + Wordpress Multisite: URL Rewrite not working in admin

I just moved a Wordpress multi-site from a Apache 2.4 Prefork + mod_php to a new server with Apache 2.4 Event + php-fpm.
The site is working well on the frontend and it is a lot faster then before due to the CGI, but... the Wordpress administration panel is working just for the main site (and network administration).
The admin area for the second site is no more working, but the frontend is working great.
Examples
http://www.example.com/en/wp-admin/ => works
http://www.example.com/en/wp-admin/post-new.php => goes on error 404
I tried to debug the rewrites, but the unique log I have (also using Debug Level 8) is
[proxy_fcgi:error] [pid 13700:tid 140381047965440] [client X.X.X.X:54354] AH01071: Got error 'Primary script unknown\n', referer: http://www.example.com/en/wp-admin/
Follwing my configurations.
Any help appreciated. Thank you.
Virtual Host
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot "/srv/www/example.com/public_html"
<IfModule mpm_event_module>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/srv/www/example.com/public_html/$1
</IfModule>
<Directory "/srv/www/example.com/public_html">
AllowOverride all
Require all granted
</Directory>
ErrorLog /srv/www/example.com/logs/error_log
TransferLog /srv/www/example.com/logs/access_log
</VirtualHost>
.htaccess
<Files "xmlrpc.php">
Order Allow,Deny
Deny from all
</Files>
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(admin|content|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+]/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Not sure if you found the solution. Just like to share our solution to this issue.
We've just added the lines below to the apache config. This will do the forwarding to FPM for all items in the regex.
ProxyPassMatch ^/([_0-9a-zA-Z-]+/)?(wp-(admin|activate|blog-header|comments-post|config|cron|links-opml|load|login|mail|settings|signup|trackback)\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$2
I add a different solution because #parpar's one, although it is working for me, it continues to throw proxy_fcgi errors:
[proxy_fcgi:error] Got error 'Primary script unknown\n'
The solution consists in removing the ProxyPassMatch way to call PHP FPM and including a handler to manage PHP calls into the Directory environment:
<Directory "/path/to/host/root">
# rest of configuration...
<FilesMatch \.php$>
SetHandler "proxy:unix:/path/to/socket.sock|fcgi://localhost"
</FilesMatch>
</Directory>
As I moved a WordPress multisite from a local XAMPP installation to a Ubuntu 18.04 server with Apache 2.4.29 and php-fpm I had the exact same issues and thus found this post.
For everyone also struggling with this, I found the following ressources helpful, however they did not work for me out of the box:
Same issue, different soloution approaches, which however did not work for me out of the box: https://serverfault.com/questions/450628/apache-2-4-php-fpm-proxypassmatch
Apache Doc on php-fpm with helpful and explained examples and even examples for Wordpress (however nothing multisite specific):
https://cwiki.apache.org/confluence/display/httpd/PHP-FPM
https://cwiki.apache.org/confluence/display/HTTPD/PHPFPMWordpress
Instead of using ProxyPassMatch I ended up using the following Apache configuration in the virtual host for the migrated page:
...
<FilesMatch "\.php$">
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/"
</If>
</FilesMatch>
...
With this configuration the Wordpress Mulisite .htaccess is recognized by apache and thus the Rewrite rules for multisite routes are applied. Due to the if statement only existing php files are passed to php-fpm.
So far both main and /en/ routes resolve correctly for frontend and admin pages.

Wordpress “Post name” permalinks not working

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.

wordpress permalinks not working - htaccess seems ok but getting 404 error on pages

I updated the permalink structure to /%postname%/ and this updated my .htaccess with:
# 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
But I still get 404 errors on the pages. Are there any other settings that I need to change?
Edit: if it helps the apache log seems to be looking directly in the permalinked folder. I.e.:
[Wed Oct 16 11:12:32 2013] [error] [client xx.xx.xx.xxx] File does not exist: /var/www/exampledomain/news, referer: http://exampledomain.com/
For other people landing on this page -
Another issue could be (If you are using Apache as your web server) is your httpd.conf or your sites-available/sitename.conf file needs editing.
Your web directory will need to allow the .htaccess file to override it's settings.
look for your web dir in the file - it will be in the bulk of the conf file or segregated into a VirtualHost section.
<Directory /path/to/site>
#add the following setting to allow .htaccess in your web dir to work
AllowOverride FileInfo
#other settings ---
</Directory>
This will allow you to set up WordPress URLs however you want, within WordPress.
***Edited - Thank You nietonfir For update. Use the least amount of privilege at first. If this doesn't work then replace AllowOverride FileInfo with AllowOverride All
There can be multiple things preventing the rewrite rule from working. My ubuntu server needed 3 things changed to get permalinks working.
In newer versions of apache2, you need to enable the module:
sudo a2enmod rewrite
sudo service apache2 restart
You may also need to modify the apache2.conf file.
sudo nano /etc/apache2/apache2.conf
Change your web directory override rule to AllowOverride All.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that, restart the service again.
The .htaccess file in the WordPress install directory needs to be owned or readable/modifiable by the webserver.
This can be accomplished by changing owner to www-data (usually the webserver user), or changing permissions.
sudo chown www-data /var/www/wordpress-install/.htaccess
OR
sudo chmod 664 /var/www/wordpress-install/.htaccess
Login to your Wordpress admin backend and save the permalink settings, and they should hopefully be working.
This is now solved. I hadn't enabled mod_rewrite. So I did this:
$ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
$ service apache2 restart
* Restarting web server apache2
You would want to tell apache to follow your .htaccess file. You can do this by editing the apache.conf file
$sudo nano /etc/apache2/apache.conf
Scroll down to the line
By default it will be:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
change the value of AllowOverride to All so now it becomes:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Press ctrl+x and press y to save the configuration file. In order to make this changes to server first enable the mod_rewrite by.
$ sudo a2enmod rewrite
And then restart the server
$ sudo service apache2 restart
Done!
Source: https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/
use below .htaccess code, just put your project name (which is in www directory) in below code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project_name/index.php [L]
</IfModule>
# END WordPress
Thanks
I was facing with the same problem and had one more thing to look for.
Here is what you need to do for wordpress permalinks work properly:
Make sure you have the proper permission modes for files and folders in your wordpress directory:
sudo find . -type f -exec chmod 644 {} +
sudo find . -type d -exec chmod 755 {} +
For permalink structure make sure mode_rewrite is enabled in apache:
sudo a2enmod rewrite
sudo service apache2 restart
One more thing to check if this describes your problem:
htaccess and mod_rewrite are set up correctly
404 error on some permalinks but not others
Ensure that there are no existing .php files or directories in the same folder as your Wordpress install with names matching a Wordpress permalink.
For example, if you have the following Wordpress page permalinks:
example.com/name_one/
example.com/name_two/
and the directory containing your Wordpress install includes the following file:
name_one.php
then this will be the result:
http://example.com/name_two/ – this permalink will work
http://example.com/name_one/ – this permalink will NOT work
More importantly, the second URL will give a 404 instead of running name_one.php, meaning this problem is hard to diagnose, as it can give the same symptoms as an incorrectly written .htaccess file.
If you are setting up a new or cloned site on ubuntu, remember to symlink the site configuration file e.g. /etc/apache2/sites-available/your-file.conf to the /etc/apache2/sites-enabled folder so apache loads it.
Just run: sudo a2ensite your-file.conf, then sudo service apache2 reload.
sudo a2dissite your-file.conf to remove symlink i.e. disable config.
Users of WAMP (Windows): Some versions of WAMP (all versions?) do not enable mod_rewrite or permit following SymLinks by default. To enable the required functionality navigate to the apache/conf/httpd.conf file, open with a text editor and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line). Then further down in the same file there is a section that starts with the line "Options FollowSymlinks". Change the second line in that section from "AllowOverride none" to AllowOverride all. Save edited httpd.conf and restart all WAMP modules. Your permalinks should now work.
For more details, Fixing Permalink Problems
Yet another possibility: I just updated my macOS which always screws up the Apache config file. Among other things, I also had to re-enable the mod_rewrite module. Find the line that says,
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
And remove the hash so it says,
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
If you are using Apache, double check no errors in Directory in VirtualHost, Apache wont warn you if you input an incorrect directory:
<Directory /var/www/html/site/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /var/www/html/site/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>

How to remove /drupal from URL in Drupal 7 when installation is in the associated sub-directory

In Drupal 6 I was able to successful install Drupal in a subdirectory called drupal and then reference the site without having to use example.com/drupal.
In Drupal 6 to get this to work I did the following:
- Created an .htaccess file in the root directory where /drupal was created. The file contents was:
Options -Indexes
RewriteEngine On
RewriteRule ^$ drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/$1
Updated the drupal/sites/default/settings.php file to have the $base_url defined as:
$base_url = 'http://example.com';
When I try and do the same thing for Drupal 7, only the front page can be displayed, all the pages fail quite horribly (or only display the front page). I have also tried uncommenting the RewriteBase lines in /drupal/.htaccess. First I tried RewriteBase /drupal and then tried RewriteBase /. But both attempts failed. I never needed to do this with D6, but I thought I would rule out this possible fix.
I am currently testing the new Drupal 7 install using xampp (version 1.7.4) with the example.com site under htdocs (i.e. xampp/htdocs/example.com/drupal). The Drupal 6 site is within the same xampp installation, but of course with a different directory path (e.g. xampp/htdocs/d6example.com/drupal). Note that I also have the Drupal 6 installation running on a production server with only the $base_url variable value changed.
So, how can you install Drupal 7 in a subdirectory and then run it from that directory without having the directory name in the URL?
Note I am installing Drupal 7 in a subdirectory as it allows for easier upgrading between new releases of the Drupal 7 core.
Try with this :
RewriteEngine On
RewriteBase /example.com
RewriteRule ^$ drupal/ [L]
# rewrite rules for drupal files
RewriteCond %{DOCUMENT_ROOT}/example.com/drupal/$1 -f
RewriteRule ^(.*)$ drupal/$1 [L,QSA]
# rewrite rules for drupal paths
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/index.php?q=$1 [L,QSA]
Put this .htaccess file in example.com directory.
You don't have to modify drupal7 .htaccess
On Apache server, add this to the root .htaccess file.
RewriteEngine on
RewriteRule (.*) drupal/$1 [L]
Update the drupal settings.php file (in /drupal/site/default/ directory) so that the $base_url line reads:
$base_url = 'http://www.example.com';
I answered a very similar question on this here:
Two Drupal installation on the same server
My answer to your question is the same, I recommend eschewing the rewrite method in favor of the virtual host method as described below (which is just an excerpt of what I answered in the link above):
...
To do this correctly you must first enter the following line (or un-comment the line if >it already exists):
NameVirtualHost *:80
Next you must create the two virtual host entries. One will be similar to the following:
<VirtualHost *:80>
ServerName your.url.fortheroot
ServerAlias alternate.url.fortheroot
DocumentRoot "/path/to/webroot"
</VirtualHost>
The next entry would be similar to the following
<VirtualHost *:80>
ServerName your.url.forthesubfoldertest
ServerAlias alternate.url.forthesubfolder
DocumentRoot "/path/to/webroot/test"
</VirtualHost>
...
In your case, however, you would only require one virtual host entry & not two.
Additionally, it should be noted that, should you desire to serve a site from a location NOT in your webroot then you would also need a
<Directory></Directory>
entry to tell Apache what access to give to visitors (NOTE: in Linux the Apache user should be made owner of the files [or permissions should be set in a method that still allows the apache user rights to serve the files if you want to avoid giving it ownership])

Resources