I have created a folder within WordPress public_html folder and created a test.php file in it as below.
www.mysite.com/myfolder/test.php
When I navigate to this url, I get page not found 404 error. All other files in myfolder, e.g. test.txt load without any issues. It's just php files that are not running. Could anyone please help?
My .htaccess file is
# 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
WordPress has its own .htaccess that is probably treating your URI as some sort of "Search Engine Friendly" thing, and translating it into some other format that WP is expecting. For example, http://www.mysite.com/myfolder/test.php might get rewritten to something like http://www.mysite.com/myfolder/index.php?target=test%25php. That would give a 404 error from within WP (not a real server 404 error). Perhaps something can be done from within WP's configuration, or you could modify the .htaccess to tell it specifically not to rewrite test.php.
This is weird since WP leaves your files alone due to RewriteCond %{REQUEST_FILENAME} !-f condition.
Try creating a myfolder/.htaccess file with this line:
# just one line here
RewriteEngine On
This will basically nullify all rewrite rules of parent folder.
Please check file-folder permission of myfolder. It should not be 777 instead it should be 755 on your server.
Please refer Wordpress php file execution
Related
I started using wordpress with my website (through 000webhost) and then I realized that's not really what I want. Not at all. So I went through and deleted all the files. There was a .htaccess file (for Wordpress) and one called .htaccess_origional. I accidentally deleted the original one and now I'm stuck with a Wordpress one that won't work. It was a file with no restrictions or modifications. I remember that it only had one line. Does anybody know how to get it back? Thanks in advance!
You just have to visit Settings > Permalink and save. It will re-generate the .htaccess file.
If you want to create the initial .htaccess file configuration. Here is the initial .htaccess configuraiton
# 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
Reference: https://www.hostinger.com/tutorials/create-default-wordpress-htaccess-file
It's been a while since I last used their service but if I recall correctly you can rebuild your webdir (or whatever it's called).
You'll have to search for this function in your control panel.
When you click this it will reset your server so BE SURE TO HAVE A BACKUP.
I got a hosting with WordPress engine installed and inside the root of WP engine folders I've created another web application which is having problems with URLs containing .profile word. When this text is added to URL I'm always receiving 404 error.
Here's an example:
WordPress blog URL: https://mainsite.com
Sub web application folder name: webapp
Sub web application access URL: https://mainsite.com/webapp/
So, when I try to access URL like this: https://mainsite.com/webapp/login.php?code=user.profile I'm receiving error 404. At the same time URL like this: https://mainsite.com/webapp/login.php?code=user.profilb is working fine (2nd URL got last letter replaced by another symbol).
I think this is an issue with WordPress default mod_rewrite settings, here they are:
# 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 got no clue at all why this could happen with .htaccess file like this. Could you suggest please?
It turned out that the issue was with mod_security of a2hosting. They were blocking all sensitive linux files and folders, like: .profile, .htaccess, .bashrc...
Hope, this will help someone.
Actually I am running a Wordpress website with a simple template.
Now for SEO and Speed optimization purposes I would like to make a custom HTML page super simple and well optimized but that is not part of the Wordpress structure.
Basically, my own HTML page.
How can I have my Wordpress thinking the main page is that HTML created page as Main page and the rest of the website managed by the Wordpress ?
My answer requires an Apache or Litespeed server (and possibly others) with mod rewrite enabled, and where AllowOverride has not limited your use of .htaccess file.
See: https://codex.wordpress.org/htaccess#General_Examples
According to the WordPress documentation on that page, if you are using an .htaccess file to handle "pretty permalinks", then it creates and uses the following basic .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
What this code does is redirect all requests that are not for an actual file or directory to the index.php file. You can modify this easily and achieve what you want. Simply changing it to something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp_index.php [L]
</IfModule>
# END WordPress
That change would redirect all requests to wp_index.php instead of index.php. So you would make that change, and then rename your index.php file to wp_index.php.
Once that is done, you can create a new index.php file and its contents can be plain HTML. Don't worry about the .php file extension. When somebody goes to your website, if they go to your homepage, the server will serve up the index.php file. For all other requests the server will use wp_index.php and WordPress will handle the request.
Please keep in mind that there are some differences in how .htaccess files work, depending on your server. If my changes don't immediately work, tweaking the .htaccess file contents may be necessary.
I am running wamp on win7 just in case. I am trying to route all requests through a route.php to get clean URLs. Below is my htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !(auth|folder2) [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*) ./route.php?path=$1 [L]
As you can see the rule should apply to all files, and it did when I ran it on my old wamp installation. Now after copying the files to a new system, for some reason, the rule seems to work for all links except index.php. So if I try http://localhost/proj, I get no routing in the new system. Any ideas?
And before anyone asks, yes rewrite_module is on, and the htaccess is being read and executed cause it works for all other links like http://localhost/proj/users and also because if I try putting garbage values in the htaccess it throws a nice 'internal server error'.
I'm guessing you have an index.php in that folder, and this condition:
RewriteCond %{SCRIPT_FILENAME} !-f
...tells apache to perform the rewrite only if the file does not exist.
I would suggest or renaming the file, as you'll need that condition to route static assets like images, scripts, etc.
If there is no index.php (or index.htm[l]) in that folder, just define route.php as the default file in that directory. In your .htaccess:
DirectoryIndex route.php index.php index.html index.htm
(Be aware that this will also apply to any sub-directories as well)
I have a proxy I've been writing with PHP for a while.
Right now, requesting a url like www.mysite.com/proxy/?folder/page.html on my server will return the page at www.theirsite.com/folder/page.html.
I basically am having my index.php file use everything past /proxy/? as the request URI for www.theirsite.com. Any images are copied to the folder /proxy/images/ and the src attributes of the <img> tags are changed accordingly. All this is working great.
Now I would like to change my script so that I will not need the ? anymore. However, the url www.mysite.com/proxy/folder/page.html would result in an HTTP request to page.html, which doesn't exist on my server.
This isn't what I want. I need index.php to be loaded instead, so it can return the page at www.theirsite.com/folder/page.html. To accomplish this, I imagine I would need to use Apache's mod_rewrite, which is working with my WordPress installation.
What would I need in my .htaccess file to do this correctly, while still allowing access to files that exist in the /proxy/images/ directory? Would this affect $_SERVER['REQUEST_URI'] at all?
RewriteEngine on
RewriteRule ^/$ /index.php [R]
Well, I got it working how I wanted. Here's the full contents of my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /proxy/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /proxy/index.php [L]
</IfModule>
Now for the url www.mysite.com/proxy/folder/page.html, index.php is loaded, and $_SERVER['REQUEST_URI'] returns /proxy/folder/page.html. Files that actually exist in the /proxy/ folder or any subfolders do not rewrite to index.php, which is what I wanted.