I have been looking at this issue for a few hours. I looked at many Stackoverflow posts, and I couldn't find the solution to my problem.
I scrapped my website a few months ago, and just started a new one shortly thereafter. However, my website does not seem to accept PHP. I don't know if the issue is with the server (when I renewed my hosting), or something else. Even calling an external PHP file, using the include function, does not work.
Anyhow, after placing the following code (along other simple coding), I see this in my PHP file when I browse the source code - meaning PHP is not working:
<?php phpinfo() ; ?>
Also, my htaccess file says the following (but I honestly have no clue what any of it means. Though I always hear people say that this file can make a difference:
# 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
It is a bit hard to understand what the actual cause is. Do you run your own webserver? If so, is it apache httpd or IIS? If you have an external hosting partner, they should be able to help you.
Why do you have a htaccess file? You only need it for things like redirect rules. If you don't use that, delete this file or empty it.
Installation of LAMP stacks :https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
Related
I have a site that is live on AWS - Wordpress, latest version, custom theme
It works fine in MAMP on my laptop, but on the live site, none of the pages besides the homepage work with the permalinks as /%post-name%/
I can make the permalinks work if I change them to default.
I don't think it has to do with htaccess, I've tried scrubbing it, we made some edits to it, and that has not made a difference.
Here are the contents of htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ucampaign/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ucampaign/index.php [L]
</IfModule>
I think it has to do with settings in the AWS instance, which I know can get complicated. But I wouldn't know where to look.
Thank you for looking at this, if there's more information needed to figure this out, I will be happy to provide :-)
Looks like a missing mod_rewrite. check apache config for that. Also, make sure Apache is reading the .htaccess file. When I say check to make sure the .htaccess is being read, does the server throw an error when you place junk inside the .htaccess file? What type of OS are you running on AWS?
I'm having some issues figuring out how to use an htaccess file. I've got apache/php installed on an ubuntu system and mod_rewrite is turned on (php_info() states that it's in the list of loaded modules). The web server works, displays html and php files, so I'm happy with that.
What I'm trying to figure out now is how to use an htaccess file properly. I created a directory, /data, with an index.php file in it. All I want it to do at the moment is just display the $_REQUEST variable so I can see if things are working the way I assume they should.
Example: If I type in the following URL: localhost/data/info1/ I want the htaccess file to access localhost/data/index.php?request=info1
However, no matter what I enter in to the htaccess file, I keep getting 404 errors, and I'd like to understand why.
Here's my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule data/(.*)$ data/index.php?request=$1 [L]
</IfModule>
I've made no changes to the config file, to activate mod_rewrite, I used the ubuntu a2enmod command so ubuntu did it for me. After that, I restarted apache.
What I can't figure out is why this doesn't work. My assumption is that there's still some sort of configuration I need to do on the server end, but I honestly don't know what. Is there any advice anyone can offer me?
Here's the fix:
RewriteRule ^data/(.*)$ data/index.php?request=$1 [L]
(You were missing a ^)
EDIT:
In the OP, you have another leading / in the URL example, in this case it'd be:
RewriteRule ^data/(.*)/$ data/index.php?request=$1 [L]
I have just had a problem with a Codeigniter site where, after the hosting company had migrated files to a new server, I could no longer navigate away from the home page. I Googled a forum with a similar issue and the answer was my htacess file. It was previously like this:
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
and the given solution was to add a '?' character after 'index.php'. I did that and everything then worked OK.
I have tried hard to understand htaccess code and syntax and read many documents but they might as well be written in Chinese for all the sense I can get out of them. So can anyone explain why that additional '?' was needed and what it did? And if you can explain the rest of the code too I would be eternally grateful!
Your new host's php handler or webserver isn't setup to handle PATH INFO, or the stuff after the script (index.php) that's part of the actual path, e.g.
/index.php/this/is/part/of/the/path_info
The index.php script is executed, and everything after can be fetched via "PATH_INFO". If the server doesn't handle this, code igniter can optionally handle the path passed in as the QUERY STRING. Which are parameters that follow a ?.
None of this has anything to do with htaccess or mod_rewrite. It's just the way URLs and handlers work.
TL; DR: I would like to hit the index-api.php file if api is found in the URL, but then simply keep all other requests pointing to the site/dist directory as if it were the 'root' of the site.
So, I've spent way too many hours on this and trust me, I've dug through all of the resources for mod_rewrite. I guess I'm just not quite understanding and figured I'd ask on here.
What I want to do, in theory, seems simple. I'm building a single page application (Angular App) using Grunt, outputting that to a the root of a WordPress install. The WordPress install is simply serving up an API using the WordPress JSON API plugin, so I want the root of the site to hit my Grunt directory (located at site/dist/index.html), but all requests to siteurl.com/api to hit the index.php file and proceed normally.
Keep in mind I have other assets / images located in this site/dist directory, so ideally, it would be awesome if all requests to the site root would simply use this folder as the "base" of the site (e.g. a request to siteurl.com/images/testimage.jpg pulls from site/dist/images/testimage.jpg).
I feel like I'm onto something here and am surprised I couldn't find anything that directly tackles this issue.
What I've done now is renamed the index.php from WordPress to index-api.php and left it the same:
index-api.php:
<?php
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wordpress/wp-blog-header.php');
// phpInfo();
.htaccess:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ index-api.php [L]
RewriteRule (.*)$ site/dist/index.html [L]
</ifModule>
I tried a myriad of other efforts from a few posts trying to get this working, and it seems to me like it should work fine. The funny thing is, if I comment out the last line RewriteRule (.*)$ site/dist/index.html [L] the api request works normally as expected, so I know I'm close.
Any suggestions?
Would appreciate anyone's help on this, it's been really confusing!
In the first place you'll need to make sure that requests made to /index-api.php are not matched and rewritten by the second rule. In the second rule you can use $1. $1 will be replaced with whatever was matched in the first capture group. We'll also need to make sure that the second rule will not match what it rewrites, or we'll end up with an infinite loop and an internal error.
You can use the $1 in the first rule too, as I show below:
RewriteRule ^api/(.*)$ index-api.php?url=$1 [L]
RewriteCond %{REQUEST_URI} !^/site/dist/
RewriteCond %{REQUEST_URI} !^/index-api\.php
RewriteRule (.*)$ site/dist/$1 [L]
I recommend reading the documentation of mod_rewrite to get a better understanding how you can use it and what things you have at your disposal while rewriting url's.
I am trying to perform this type of rewrite
http://sitename/foo/var1/var2 -> http://sitename/foo/index.php?/var1/var2
This is my .htaccess file(placed in the directory foo):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
In my php script I am displaying the values of $_SERVER['REDIRECT_QUERY_STRING'] and $_SERVER['REQUEST_URI']
If I request a URL like http://sitename/foo/bar the values as expected are bar and /foo/bar respectively.
This also works as expected for: http://sitename/foo/admin and http://localhost/foo/bar.
However when I try to access http://localhost/foo/admin (using localhost instead of sitename) the REQUEST_URI changes to /admin/?admin (this is how it displays in the address bar too, i.e http://localhost/foo/admin/?admin)
I searched for any .htaccess files that might be conflicting and also turned on mod_rewrite logging at level 6 but was unable to find any info.
I have no clue what might be causing it. It would be great if I could know what might be causing this, otherwise I might switch to nginx.
Thanks all for replies. This was some weird server configuration error, things seem to be fine on the new VM I installed. #Dan Grossman , thanks for your suggestion about using $_GET, some of my code is simpler than earlier.