Using non-wordpress PHP pages on the same ftp server - php

I have Wordpress site set up on the route of my ftp server, I am trying to add PressKit() to my site in the directory /Press . This uses an index.php file to display the html, however wordpress seems to show a 404 error when trying to access it. I have tried adding a .htaccess to the subdirectory, but with no luck.
I'm wondering how to prevent the 404 error from displaying? As I am certain the page is there, as a few times when I use the full url (including index.php) it will open, but only on my machine.
Apologies if this is simple, web dev isn't really my field.
Cheers.
Edit: Works now, but case sensitive
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(Press) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Open the .htaccess file, in the root of your WordPress installation (not the sub-folder), and look for the #BEGIN WORDPRESS block. You can replace it with this
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(Press|folder2) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
You can add more folders for WordPress to ignore, using the pipe | where you currently see the words Press|folder2. You may also remove the "folder2" reference, that's just an example

Related

Add Subdirectory to WP-CONTENT URL using HTACCESS in Wordpress Multisite

I'm in the process of transitioning my single site WordPress installation into a multi-site. I'm trying to fix the broken CSS/JS from my main site.
I currently have two sites on my network:
http://www.example.com (primary)
http://dev.example.com (secondary)
My multi-site installation is inside of a subdirectory we will call "wordpress". So the file path looks like public_html/wordpress.
My goal is for neither site to have the "wordpress" subdirectory in the URL. Everything seems to be working except for broken CSS and JS on the primary site (the secondary site looks fine).
When inspecting the code, all of the CSS and JS calls point to http://www.example.com/wp-content/ but the files are not found there. The files will be found if I go to http://www.example.com/wordpress/wp-content in my browser. I want to hide the wordpress folder and still be able to retrieve the files.
I'm confused on how to setup the HTACCESS file. I already made some initial changes to it in order to get the multi-site within the subdirectory working. These were all following guides I found on StackOverflow and elsewhere online in regard to how to move your site into a multi-site with subdirectory and hiding the subdirectory. I haven't found anything about addressing the broken CSS/JS issue.
I figured I need to make updates to one or more of 3 HTACCESS files.
1.) public_html/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ /wordpress/index.php [L]
</IfModule>
2.) public_html/wordpress/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [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-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
3.) public_html/wordpress/wp-content/.htaccess
This file didn't exist but I created it. My thinking was that files are being called without the wordpress subdirectory but they need to act like they have the subdirectory included in them. For example, currently http://www.example.com/wp-content/uploads/image.jpg is broken but http://www.example.com/wordpress/wp-content/uploads/image.jpg works. I want it to be the other way around or I want both paths to work.
<IfModule mod_rewrite.c>
RewriteEngine on
# ADD WORDPRESS IF URL DOES NOT HAVE IT
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteRule ^(.*)$ /wordpress/$1
</IfModule>
I've tried adding different lines to the various HTACCESS files but none of them worked. I also not sure what line number I should insert a new rule. It's possible that one of my new rules is correct but it is in the wrong place. Below is one that I really thought would work but didn't.
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
First, you should remove all the .htaccess files and keep only the one in the root: public_html/.htaccess
Second, your last rule isn't working because is slightly wrong.
You should change it from:
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
To:
RewriteRule ^wp-content/(.*)$ wordpress/wp-content/$1 [L,NC]
Because you don't need the starting / and you don't need to 301 redirect. You want to keep your wordpress folder hidden and just map the requested URLs from wp-content/(.*) to wordpress/wp-content/$1
Also, this rule must be the first in your .htaccess file to have priority over following default Wordpress rules. Your final and only .htaccess from public_html/ should look like this:
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/(.*)$ wordpress/wp-content/$1 [L,nc]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I hope it helps you.
You shouldn't have to set up several .htaccess files in your sub-directories.
The only .htaccess file that need to be modified is the one located in the application root directory. In your case, it seems to be your public_html/.htaccess or your public_html/wordpress.
Now by default WordPress generates an .htaccess file in that directory which looks something like the following:
# 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
In order to rewrite your URLs, you need to add your RewriteRules before the WordPress code block.
Since RewriteRules are processed from top to bottom, if the request is first rewritten to index.php by the WordPress block, then your rule will never be processed.
Therefore your RewriteRule:
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
should be enough if it's placed at the top of the root directory's .htaccess, and remove the .htaccess file in the sub-directories
Most Multisite networks are installed in the root directory of your site. This means that if your server is using example.com, then this will be the URL for your base site on the network.
If you’ve installed WordPress Multisite in a subdirectory, then you can’t use subdomains.
If you already have a single site installation at example.com, and you add another WordPress installation in a subdirectory running Multisite, then its address will be example.com/wordpress.
Any site you create on your new network will be at example.com/wordpress/my-new-site. Creating a subdirectory would be impossible here, as it would have to be at an address like example.com/wordpress/my-new-site.network Which just doesn’t work.

WordPress Redirect all file downloads to subdomain

I have a new WordPress site, example.com, with the old Drupal site archived at archive.example.org. Many files on the old site had a URL like so (ex: example.org/files/foo.pdf), but all those links out there in the internet are breaking because all those file downloads need to be redirected to archive.example.org/files/foo.pdf.
Can creating redirects (I'm guessing .htaccess is the best bet) work for file downloads as well? Is there a simple redirect to send all old links to the archive subdomain?
I have tried:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.org%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
...with no luck so far.
Thanks for any help!
If you want to redirect all files/* requests to the new domain and keep everything else from WordPress, you need a condition for the rule, which checks for files
RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.com%{REQUEST_URI} [R,L]
When everything works as it should, you may replace R with R=301. Never test with R=301.

Mod_Rewrite issue - Show Wordpress Content vs. Listing Directory

I have a Wordpress blog for our church. We have an actual directory called "sermons" and we also have a section on the site called sermons. I need to be able to go to http://ourchurch.org/sermons and get a listing of sermons or http://ourchurch.org/sermons/sermon-title/ and get the sermon.
However, if I go to http://ourchurch.org/sermons/speakername/sermon.mp3 I need it to play or download the mp3. The same would go for pdf files.
Everything is working EXCEPT the sermon listing page. When I go to: http://ourchurch.org/sermons it gives me a directory listing. I need it to allow the WordPress rules to work to direct it to the correct content page.
Here is what I currently have:
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# 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]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/sermons/(.+)/*\.(mp3|pdf)$ [NC]
RewriteRule ^(.*)$ - [L]
</IfModule>
# END WordPress
What am I doing wrong?
Thanks in advance for your help!
Perhaps adding this at the top of your RewriteRule list?
It routes requests that end with sermons or sermons with a / to index.php - which is WordPress.
RewriteRule sermons/?$ index.php [L]

.htaccess WordPress ignore directory and remove index.php from that directory

So I know how to tell WordPress how to ignore a directory using the .htaccess file but I want to be able to remove the index.php from inside that directory too so I can access like this:
wordpresssite/directory/controller/function = wordpresssite/directory/index.php/controller/function
I've been trying but I'm clearly not very good at writing .htaccess files.
Thanks
My .htaccess file
The wordpress site is called smartronic and the subdirectory I want to ignore and remove index.php from is /mailin
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /smartronic/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(mailin|mailin/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /smartronic/index.php [L]
</IfModule>
# END WordPress
At the moment going to smartronic/mailin takes me to the xampp root page or a 404 page
To insert index.php into a fixed URL, you can use a simple RewriteRule
RewriteRule ^mailin/controller /mailin/index.php/controller [L]
If controller is variable, you need to capture this part with (...) and append it after the substitution with $1
RewriteRule ^mailin/(.*)$ /mailin/index.php/$1 [L]

Error 403 Forbidden if I go to a wordpress url that is the same of an existing directory

I am developing a new site in wordpress, my site is completed and I want to replace it with my old site (not a wordpress site, a php and html site).
The moving wordpress procedure is correct (I have installed wordpress in a subdirectory), i can see everything but when i go to a page like www.site.com/mypage which is the same name of an existing folder in my site (www.site.com/mypage) i get the 403 error.
in the folder there is not a index.php/html file.
I want to keep this permalink structure and the folders name..
I do not want to show the list of files in the directory, but only the page I have created in wordpress.
how can I fix it?
thank you
htaccess here:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Just ran into this problem and found an answer here: http://jeffreybarke.net/2011/01/wordpress-permalinks-403-forbidden-error/
In short, you need to write a few lines into your .htaccess which specify the folder names with the problem:
# Fix 403 errors on existing directories; WordPress overrides.
RewriteCond %{REQUEST_URI} ^/(folder1|folder2|etc)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

Categories