How to write .htaccess rewrite rule - wordpress

I installed a online website onto my ubuntu machine for development purposes.
Everything is working except for one section of the site. When I point the browser to http://localhost.000-wordpress.co/app I get the below error in my apache2 error log:
[Fri Jan 17 16:57:03 2014] [error] [client 127.0.0.1] File does not exist: /var/www/app, referer: http://localhost.000-wordpress/
The server is looking for the app folder in the wrong location on my file system. So I have created a .htaccess file but I don't know how to write a rewrite rule for this.
How should I code a rewrite rule to tell the server to go to /home/ross/public_html/000-wordpress/public/app instead of /var/www/app?
This is 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
Update
After following Covner's advice I updated my apache2.conf file with:
Alias /app /home/ross/public_html/000-wordpress/public/app
<Directory /home/ross/public_html/000-wordpress/public/app>
Order deny,allow
</Directory>
But this has thrown back two different errors:
[Sat Jan 18 23:35:55 2014] [error] [client 127.0.0.1] PHP Warning: require_once(/home/ross/public_html/000-wordpress/public/app/../vendors/yii/framework/yii.php): failed to open stream: No such file or directory in /home/ross/public_html/000-wordpress/public/app/index.php on line 12, referer: http://localhost.000-wordpress/
[Sat Jan 18 23:35:55 2014] [error] [client 127.0.0.1] PHP Fatal error: require_once(): Failed opening required '/home/ross/public_html/000-wordpress/public/app/../vendors/yii/framework/yii.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ross/public_html/000-wordpress/public/app/index.php on line 12, referer: http://localhost.000-wordpress/

You don't want to do anything in htaccess, just use the normal configuration file (they're all created equal)
Alias /app /home/ross/public_html/000-wordpress/public/app
<Directory /home/ross/public_html/000-wordpress/public/app>
Order deny,allow
</Directory>

Related

Permission denied on Centos7, Apache, Mod Passenger and Ruby 2.6.3

I never tried working with Cent-OS for hosting my Rails applications. I was using before and now I got a server which is running Cent-OS 7. I installed Apache, Phusion Passenger, RVM, Ruby 2.6.3 and bundle updated the Rails app. Everything was fine up to this.
I added the Virtual-Host and restarted the Apache2 server, I got 403 Forbidden message from the browser.
Also I checked the error_log I got the following errors.
[Tue Feb 11 08:34:14.377938 2020] [core:error] [pid 125490] (13)Permission denied: [client 172.69.78.16:30474] AH00035: access to / denied (filesystem path '/home/santosh/sites') because search permissions are missing on a component of the path
[Tue Feb 11 08:34:14.593925 2020] [core:error] [pid 125490] (13)Permission denied: [client 172.69.78.16:30474] AH00035: access to / denied (filesystem path '/home/santosh/sites') because search permissions are missing on a component of the path
The virtual host:
<VirtualHost *:80>
ServerName domain.com.np
ServerAlias www.domain.com.np
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# ModPagespeed on
# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /home/santosh/sites/app/public
PassengerRuby /home/santosh/.rvm/gems/ruby-2.6.3/wrappers/ruby
# Relax Apache security settings
<Directory /home/santosh/sites/app/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
And the permission of the app directory is as:
drwxrwxr-x. 4 santosh santosh 31 May 18 2019 app
I couldn't figure out what I am missing. Please help me.
Have you checked the folder permissions on the server, try running 'ls -l' on your folder.

How can i diagnose Apache errors on Wordpress and on shared hosting? Mainly LimitInternalRecursion

I have few problems with my wordpress site which is building high number of Apache errors.
[Wed Mar 06 18:21:14.844492 2019] [core:error] [pid 28034:tid 140475830826752] [client] AH00125: Request exceeded the limit of 10 subrequest nesting levels due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Others are
- connection resetted by peer ([pid 17983:tid 140475847612160] - ap_pass_brigade failed in handle_request_ipc function)
- Broken pipe: [client] mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
But the worst is LimitInternalRecursion which is appering whole day whole night thousand times
Earlier i thought that i repaired this problem, by deleting google sitemaps, disabling google analytics and yoast seo (which is giving these maps)
My htacess is default:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
+w3 total cache codes and rewrites (paste it here?)
I have redirection from other domain and in other htacess one line:
Redirect 301 / http://swiadomosc-zwiazkow.pl/
(i'm not using www prefix)
I have disabled all plugins and problem persists. Maybe something with database?
Problems are more often when im using wp_admin

Error AH00124 during Symfony 4 server configuration

I currently am trying to deploy my Symfony 4 website on a hosted VPS, I did setup everything quite successfully, installed Apache2, PHP 7.2, MySQL server and phpmyadmin.
I then started configuring my server acordingly to host a Symfony 4 website, and before deploying my own application I tried to deploy a smaller one so that I would know that at least some part worked with a no-database no-bundles application.
When I try to access my website nothing happens, the following error log is generated in /var/log/apache2 :
[Wed Jul 11 14:06:08.580654 2018] [core:error] [pid 13404] [client 37.97.69.85:52997] AH00124: Request exceeded the limit of 10 internal redirects due to probable
configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jul 11 14:06:41.901738 2018] [php7:error] [pid 13423] [client 37.97.69.85:44931] PHP Fatal error:
Uncaught Symfony\\Component\\Dotenv\\Exception\\PathException: Unable to read the "/var/www/releases/20180710151554/public/../.env" environment file.
in /var/www/releases/20180710151554/vendor/symfony/dotenv/Dotenv.php:54\nStack trace:\n#0 /var/www/releases/20180710151554/public/index.php(15):
Symfony\\Component\\Dotenv\\Dotenv->load('/var/www/releas...')\n#1 {main}\n thrown in /var/www/releases/20180710151554/vendor/symfony/dotenv/Dotenv.php on line 54
[Wed Jul 11 14:33:33.702774 2018] [core:error] [pid 13442] [client 37.97.69.85:53026] AH00124: Request exceeded the limit of 10 internal redirects
due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jul 11 14:38:07.055940 2018] [core:error] [pid 13642] [client 37.97.69.85:54628] AH00124: Request exceeded the limit of 10 internal redirects
due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jul 11 14:51:50.406171 2018] [php7:error] [pid 13793] [client 37.97.69.85:55651] PHP Fatal error: Uncaught RuntimeException:
APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file. in /var/www/demo/public/index.php:13\nStack trace:\n#0 {main}\n thrown in /var/www/demo/public/index.php on line 13
I believe this comes from the website configuration file looping somewhere, I have seen cases online where the .htaccess and the configuration file were looping but here I do not have an .htaccess file anywhere as I deleted it.
He is my website configuration :
<VirtualHost *:80>
ServerName vps562960.ovh.net
ServerAlias vps562960.ovh.net
DocumentRoot /var/www/releases/20180710151554/public
<Directory /var/www/releases/20180710151554>
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/crvfakeexample.com>
# Options FollowSymlinks
# </Directory>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/releases/20180710151554/public/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/vps562960.ovh.net_error.log
CustomLog /var/log/apache2/vps562960.ovh.net_access.log combined
# optionally set the value of the environment variables used in the application
#SetEnv APP_ENV prod
#SetEnv APP_SECRET <app-secret-id>
#SetEnv DATABASE_URL "mysql://db_user:db_pass#host:3306/db_name"
</VirtualHost>
I'm starting to lose hope on deploying that website. Has anyone faced a similar case or do any of you know what I'm doing wrong?
Thanks in advance.
Most probably the problem is that Apache server doesn't set env variables into PHP global array $_SERVER. But symfony tries to find env variables exactly in $_SERVER array. Either update public/index.php and replace all $_SERVER with $_ENV or uncomment SetEnv directives in Apache website conf.

WordPress on Localhost with .htaccess

I have installed WordPress (latest) on a local server which is running on UniServer.
The installation finished OK and I was able to navigate around the admin area and added a couple of posts.
Looking from the front end, everything worked.
I then changed the Permalink setting to 'Post name' and, when I saved it I revceived an error "Forbidden - You don't have permission to access /wp-admin/options-permalink.php on this server."
On checking I found that if I deleted the .htaccess file I regained access and could reset the Permlink setting to 'Plain'.
Changing to anything but 'Plain' causes a .htaccess file to be created and no access.
The Apache error log shows the following: -
"[Wed Mar 21 12:35:04.297002 2018] [rewrite:error] [pid 14192:tid 1908] [client ::1:52537] AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions : D:/WEBS/js/wp-admin/options-permalink.php, referer: http://localhost/wp-admin/options-permalink.php"
I have used Google to search this message and have been round in circles with changes to the .htaccess file and also httpd.conf to no avail.
The .htaccess file that is created is as follows: -
# 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 followed what is posted here: [https://codex.wordpress.org/Using_Permalinks]
Any help would be much appreciated...
OK, the solution appears to be that SymLinks needs to be enabled.
So, I added the following to .htaccess
Options +FollowSymLinks
What I did not notice was that, when I changed the Permalinks option in WordPress, the code above was stripped out.
So after further searching on Google and testing with the httpd.conf file I found that by adding the following line to DocumentRoot works
Options Indexes FollowSymLinks SymLinksIfOwnerMatch
I am not convinced that I need all of the options and, time permitting, with try to understand the consequences of each one and whether they are required.
However, for now, I can access the WordPress site locally again with PermaLinks set to 'Post name'.

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.

Resources