I have correctly setup my site locally and everything works. However, when I deployed that to a blank EC2 instance, I see that wp-json (Rest API) does not work. It works only when I put an index.php in between. In other words
This works locally:
http://localhost/wordpress/wp-json
But I need to have this on the EC2 server to make it work.
http://A.B.C.D/wordpress/index.php/wp-json
On the server, I have installed apache2 and I have not messed up with the configs yet. I am familiar with wordpress but I not so much familiar with config tweaks on apache. I have also gone thru thousands of previously posted questions, but none of them seem to answer my problem.
First, you need to have by a2enmod rewrite in your terminal.
Then in your Apache Configuration file, make sure you have the following:
<Directory #Wordpress directory here#>
Options Indexes FollowSymLinks
AllowOverride All #allows .htaccess directives in the next step
Require all granted
</Directory>
Then make sure you have the following content in your root .htaccess file:
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L]
I am using Apache 2 on Xubuntu to run multiple local instances of TYPO3. Since they use different TYPO3 and therefore PHP versions, I'm using fastcgi to pass requests to the one with TYPO3 version 9.5.x to the corresponding php7.2-fpm.
However, none of the pages other than "Home", the TYPO3 backend and the phpinfo are loading. I just get a raw 404 message which looks like it's coming from apache rather than from TYPO3 itself.
The only way I can get the pages to load is when I call them using the pageID and a parameter to suppress the redirect to the "more beautiful" URL. This, and the raw error page, make me believe that the problem lies within my Apache config rather than my TYPO3 setup. It seems like every call to a specific file (/index.php, /typo3/index.php, and /info.php) works, but the routing doesn't work because the apache tries to resolve it directly to a file/directory.
This is my apache config for the problematic vhost:
<VirtualHost *:80>
ServerName test.test
DocumentRoot /var/www/foo/bar/httpdocs
# <FilesMatch \.php$>
# SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost"
# </FilesMatch>
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/php7.2-fpm.sock|fcgi://localhost/var/www/foo/bar/httpdocs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The commented part was the first try, when I noticed the problems I found the "ProxyPassMatch"-Part online and tried it out, but I have the same issues.
This is the crucial part of the rewriting in the default .htaccess (that is shipped with TYPO3):
<IfModule mod_rewrite.c>
RewriteEngine On
# ...
# If the file/symlink/directory does not exist => Redirect to index.php.
# For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
</IfModule>
Important is that all URLs that are not file requests are passed on to index.php
First, check the obvious:
Is mod_write enabled (e.g. a2enmod rewrite)?
Is the .htaccess executed? As mentioned, in the comments, AllowOverride must be set.
For example, within the VirtualHost section, put this:
<Directory /var/www/foo/bar/httpdocs>
# When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.
AllowOverride All
</Directory>
If that does not solve the problem, you can try narrowing down the problem step by step:
For example create a file /abc.txt with text "hello" in your web root. Then, add this before the TYPO3 rewrite blocks.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule /?xyz /abc.txt [L]
</IfModule>
Test the URLs /abc.txt, /xyz. They should both show "hello".
This way you can check if the rewrites work in general (without involving TYPO3). Once the test is successfull, remove again.
see also Troubleshooting in the Installation Guide, which also mentions the mod_rewrite.
Disclaimer: I don't know about the ProxyPassMatch but it seems to be generally working from what you described.
I have a rather strange issue with my website. I have just decided to remove my website from one server to a new server (I no longer wanted to use wpengine.co.uk)
I have now got the site up and running however the only issue I have is if I set the "permalinks" option to "post name" as can be seen here: http://i.imgur.com/poyRQ9x.png then I get a 404.
I have the following Apache setup on a Linux box:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
My .htaccess looks like this (for now I have set the file permissions to 666):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Lastly I have enabled as can be seen from my "phpinfo()" page.
The site does work if I use the ugly looking "plain" option... but that is obviously something I don't want.
Reboot Apache after making changes to httpd.config. (Changes to pph.ini and .htaccess don't require reboots).
And, you may need to add AllowOverride All for the document root:
<Directory /var/www/html>
# ... other directives...
AllowOverride All
</Directory>
Please remove your .htaccess file from wordpress root directory, then try to change permalink setting.
Note :- backup .htaccess file before delete it.
I hope this will work for you.
Well the answer turned out to be rather strange. It appears that for this to work I needed to install some extra PHP extensions. All I needed to do was:
sudo apt-get install php-mbstring php7.0-mbstring php-gettext
Although I think that the one that finally worked was:
sudo apt-get install php-curl
I saw warnings about this but I had no idea that that would actually stop WordPress's redirection. If somebody knows why this is the case I'd be really grateful to know.
I am trying to get mod_rewrite to work by using a .htaccess file on my localhost server.
My apache2.conf file contains:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And:
Include mods-enabled/*.load
/etc/apache2/mods-enabled/rewrite.load file contains:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
The .so file exists.
service apache2 restart shows no warnings/errors
My .htaccess contains:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /process.php?path=$1 [NC,L,QSA]
And it's located at /var/www/wp/wp-content/plugins/myplugin/
process.php contains print_r($_SERVER);
I am visiting http://localhost/wp/wp-content/plugins/myplugin/randomstring and always getting a 404 error.
I tried changing the .htaccess file to a random string trying to trigger a 500 error to make sure the .htaccess was being "executed"(?), but still getting a 404 not found error.
var_dump(in_array('mod_rewrite', apache_get_modules())); returns true
what am i doing wrong? This always works on my online servers.
Check if the module is enabled using php_info(). If there is some errors.
Try the following command.
sudo a2enmod rewrite
I think if you change (/etc/apache2/sites-available/default) AllowOverride none to AllowOverride All then it will work.
If still you are getting the error, then do the steps mentioned here.
The tutorial is bit old, but you can get the module working.
I hope this helps.
Currently I am using the hosting with lightspeed server. Hosting says mod_rewrite is enabled but I can't get my script working there. Whenever I try to access the URL, it returns 404 - not found page.
I put the same codes at another server which is running with Apache. It's working over there. So I guess, it's the .htaccess and mod_rewrite issue.
But Hosting support is still insisting with me that their mod_rewrite is on, so I would like to know how can I check whether it's actually enabled or not.
I tried to check with phpinfo(), but no luck, I can't find mod_rewrite there, is it because they are using lightspeed?
Is there any way to check? Please help me out. Thank you.
FYI: my .htaccess code is
Options -Indexes
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
I tried like this also
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
But same result.
from the command line, type
sudo a2enmod rewrite
if the rewrite mode is already enabled, it will tell you so!
To check if mod_rewrite module is enabled, create a new php file in your root folder of your WAMP server. Enter the following
phpinfo();
Access your created file from your browser.
CtrlF to open a search. Search for 'mod_rewrite'. If it is enabled you see it as 'Loaded Modules'
If not, open httpd.conf (Apache Config file) and look for the following line.
#LoadModule rewrite_module modules/mod_rewrite.so
Remove the pound ('#') sign at the start and save the this file.
Restart your apache server.
Access the same php file in your browser.
Search for 'mod_rewrite' again. You should be able to find it now.
If you are using a virtual hosts configuration file, make sure the virtual host in question has the directive AllowOverride All somewhere like this:
<VirtualHost *:80>
...
<Directory "directory/of/your/.htaccess">
AllowOverride All
</Directory>
</VirtualHost>
Basically, this states to allow processing of all .htaccess directives.
This works on CentOS:
$ sudo httpd -M |grep rewrite_module
Should output rewrite_module (shared)
console:
<VirtualHost *:80>
...
<Directory ...>
AllowOverride All
</Directory>
</VirtualHost>
sudo a2enmod rewrite
sudo service apache2 restart
If apache_get_modules() is not recognized or no info about this module in phpinfo(); try to test mod rewrite by adding those lines in your .htaccess file:
RewriteEngine On
RewriteRule ^.*$ mod_rewrite.php
And mod_rewrite.php:
<?php echo "Mod_rewrite is activated!"; ?>
PHP's perdefined apache_get_modules() function returns a list of enabled modules. To check if mod_rewrite is enabled , you can run the following script on your server :
<?php
print_r(apache_get_modules());
?>
If the above example fails, you can verify mod-rewrite using your .htaccess file.
Create an htaccess file in the document root and add the following rewriteRule :
RewriteEngine on
RewriteRule ^helloWorld/?$ /index.php [NC,L]
Now visit http://example.com/HelloWorld , You will be internally forwarded to /index.php page of your site. Otherwise, if mod-rewrite is disabled , you will get a 500 Internel server error.
Hope this helps.
If
in_array('mod_rewrite', apache_get_modules())
returns true then mod-rewrite is enabled.
you can do it on terminal, either:
apachectl -M
apache2ctl -M
taken from 2daygeek
If this code is in your .htaccess file (without the check for mod_rewrite.c)
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
and you can visit any page on your site with getting a 500 server error I think it's safe to say mod rewrite is switched on.
You can use php function
apache_get_modules
and check for mod_rewrite
<pre>
<?php
print_r(apache_get_modules());
?>
</pre>
http://in2.php.net/apache_get_modules
If you are in linux system, you can check all enable modules for apache2(in my case) in the following folder:/etc/apache2/mods-available
cd /etc/apache2/mods-available
to type: ll -a
if you want to check the available modules for php (in this case php 7 )
folder /etc/php/7.0/mods-available
cd /etc/php/7.0/mods-available
to type: ll -a
I know this question is old but if you can edit your Apache configuration file to AllowOverride All from AllowOverride None
<Directory "${SRVROOT}/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
just make a new page and add this code
<?php
if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
$res = 'Module Unavailable';
if(in_array('mod_rewrite',apache_get_modules()))
$res = 'Module Available';
?>
<html>
<head>
<title>A mod_rewrite availability check !</title></head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>
and run this page then find will able to know module is Available or not if not then you can ask to your hosting or if you want to enable it in local machine then check this youtube step by step tutorial related to enable rewrite module in wamp apache
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp server icon -> Apache -> Apache Modules and check the rewrite module option
This code worked for me:
if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) echo "mod_rewrite enabled";
else echo "mod_rewrite disabled";
First you check if the module is installed
apachectl -M
It it does not shows on the list, you must activate it:
a2enmod rewrite
Now, restart your server and test
systemctl restart apache2
You just need to check whether the file is there, by typing
cat /etc/apache2/mods-available/rewrite.load
The result line may not be commented starting with #
I was having the exact problem, I solved it by clicking custom structure, then adding /index.php/%postname%/ and it works
Hope this saves someone the stress that I went through finding what the heck was wrong with it.
Simply create a php file in root and add following code
<?php
if (in_array('mod_rewrite', apache_get_modules())) {
echo "mod_rewrite is enabled";
} else {
echo "mod_rewrite is not enabled";
}