Ignoring a subfolder with .htaccess - php

In my public_html I have 2 Folders, wordpress and tickets. I currently have the /wordpress directory working via mod_rewrite so that the URL's look nice. I'd like to setup an instance of OSTicket, and upon navigating to example.com/tickets to start the configuration, I'm hit with a Wordpress 404 error.
My root .htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/tickets/.*
RewriteRule ^tickets - [L,NC]
RewriteRule ^index\.php$ /wordpress/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
I also have a .htaccess in the tickets folder, with;
RewriteEngine off
If anyone has some insight or perhaps something I should look into it would be most appreciated, thankyou all kindly.

The condition you have is the opposite of your match. They can't both be right. Drop the condition permanently, and amend the rule to this:
RewriteRule ^tickets(?:$|/) - [L]
That ensures /tickets-foo/ still goes to WordPress and that you're not matching case-insensitively when your filesystem is case-sensitive.
Temporarily rename the tickets dir. Create another one with only an index document in it, content is irrelevant but put something in. Visit example.com/tickets and you should see your aforementioned content.
I'm betting the issue is not in the .htaccess nor WordPress.

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.

Running POST request to php script which sends contact mail from within wordpress subfolder results in 404 Not found

I've just read so much about this issue, but I'm lost here. Can't make this s*$%& work. Here's the issue. Graphic designer has a working WordPress, of which I know same as nothing, about some kindergarten in the city. She builds a landing page to throw a marketing campaign within a subfolder landing201812 inside the public_html folder of the hosting space. The WordPress is installed/deployed/whatever at the root of the site.
Site: https://www.newmills.com.ar/
Landing: https://www.newmills.com.ar/landing201812/
Directories:
public_html/
- lots_of_wordpress_rubbish
- .htaccess
- landing201812/
- sendform.php
Reading about wordpress bootstrapping way for processing all the requests, I have altered the .htaccess file in public_html so it excludes the rewriting of wordpress and goes straight to the landing site.
Original content:
# 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
Actual content
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^landing201812/?.* - [L] # My added rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
With both configurations, the static content (html/css/media) is served correctly, but, any php I would like to execute within that landing201812 folder, fails with a 404 Not Found error. I have tried also to exclude any landing201812 route with RewriteCond directives from the last RewriteRule like
RewriteCond %{REQUEST_URI} !.*landing201812.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
But the results are the same.
I am quite limited to move around the wordpress since I know nothing about wordpress. I have considered moving it to a subfolder of the public_html, but I'm afraid of breaking it, or its URLs. I have tried to disable the permalinks, but there's no On/Off switch that I could find.
Last, but in case you may wonder, I have tried including another .htaccess file inside my landing201812 folder. RewriteEngine Off did not work as much as the alternative I took from a native wordpress subfolder:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /landing201812/
RewriteRule ^.*\.php$ - [L]
</IfModule>
# END WordPress
So... does anyone know what's wrong, or even better, how to fix this issue? Everyone says on the web that I should be fine with the htaccess rule, or disabling the permalinks, or moving the wordpress to a subfolder and not the root folder. Moving it is the last thing I would like to do, because I won't know how to fix it if it breaks. Am I missing something? Is there any log I should check?
Thanks in advance for any help.
if you are using cpanel, this is not necessary to do in .htaccess
Instead, can you please keep the original wordpress .htaccess and just assign permissions with filezilla to 775 to the folder?
Also, there should be a configuration missmatch, please try re-loading the PHP version in CPANEL (with PHP MANAGER) only to that folder.
If you can provide access to the site in private, maybe I can give you a hand.
It seems to me that if you were to keep the origional WordPress .htaccess and change your file structure to the following it will work at /landing201812/:
public_html/
- lots_of_wordpress_rubbish (not my opinion, just here to match OP)
- .htaccess
- landing201812/
- index.php
The key is naming the file index.php. Otherwise, you can call the file by name like so: /landing201812/sendform.php.

Redirect URL Rewrite/Map from .htaccess

The problem is,
I want to port my current website which is built upon CodeIgniter to WordPress. I do not want to hurt my google ranking and for that, I really need to map certain URLs to an existing file and for new URLs, I will let WordPress handle it in the default way. The main problem that arises is that I do not wish to change the existing domain. I want to redirect/map the files on the same domain from my existing CodeIgniter project.
Okay, let me make it a bit more clear about the state of my problem. I copied my existing CodeIgniter project into the WordPress root folder. Now, I will let the old URL being served from my CodeIgniter project and for all the new ones I will let WordPress handle it. I will also port the existing database to the new server and create a separate one for the WordPress installation.
So, how can I map my old URLs to the CodeIgniter?
My old URLs looks something like this,
http://www.example.com/site/blog/123/abc-xyz-wxy
I want to handle these URL from CodeIgniter file and the new URLs that will be created by WordPress will be handled by WordPress which would look like this,
http://www.example.com/abc-xyz-wxy
So, far this is how my .htaccess file looks like,
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/wordpress/
RewriteRule ^site/blog/([0-9]+)/([a-zA-Z0-9-]+)/?$ codeignitor/index.php/$2
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cms/wordpress/index.php [L]
</IfModule>
END WordPress
And this thing works absolutely fine, but what I want is more of a URL masking. I want to eliminate the CodeIgnitor folder name from the URL.
For selecting the "abc-xyz-wxy" string and redirecting, try using:
RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-d
RewriteRule ^site\/blog\/123\/([a-z-]+) index.php\/$1 [NC,L] ^$1
Disclaimer: Never used CodeIgniter, so everyone feel free to correct.
In case anyone else happens upon this, I have a similar sounding use case where the application code resided inside /public_html/app/ and I wanted it redirect from /public_html/ but not show the app/ portion of it in the url. There was also an additional requirement to not route specific urls in this manner. The resulting file is below. Hopefully it helps someone on a similar journey.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
## SSL
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## DO NOT ROUTE THESE DIRECTORIES
RewriteRule ^(path-1|path-2) - [L]
## ROUTE OTHER REQUESTS TO /APP
RewriteCond %{ENV:REDIRECT_STATUS} . [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} /(.+)
RewriteRule !\.[a-z0-4]{2,4}$ /app/index.html [NC,L]
RewriteRule (.*) /app/$1 [L]
</IfModule>

Redirect to outside Wordpress

I have a folder called "stats" on my server that I cannot access anymore because wordpress redirects it to the "Page not found". This folder has nothing to do with wordpress. I have searched for a solution but nothing seems to be working. I am using the theme elegant fusion.
For clarification, the folder is on the same level directory wise as "wp-admin", "wp-content", "wp-includes".
Does anyone know how I can access my folder without going through wordpress?
Thank you in advance!
Enable searach engine optimised permalinks is the answer. I am thinking you must be using the default permalinks, by enabling seo permalinks in Settings->Permalinks in the backend will create (assuming permissions allow, if not you do it manually) an .htaccess file in the root of your install like so;
# 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
The two lines that will solve your problem are;
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Which tell wordpress to ignore any url which is for an actual directory or file. Anything else gets rewritten by Wordpress.

How to add an exception to a mod_rewrite rule (wordpress site)

I have a WordPress website im trying to call a php script that is located on the website the URL is something like this
http://example.com/folder/process.php
The problem is when I try to do this i always get redirected to the themes "not found" page.
This is the 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
If i put a test.html file in that directory it will work, and show the contents of the .html file. I think it has something to do with the .php extension it doesn't like?
If i call example.com/wp-config.php it finds that file and deosnt show a 404 page..
This Rule says "If request starts with index.php, do not rewrite and stop".
RewriteRule ^index\.php$ - [L]
Immediately before or after that line you could add something like
RewriteRule ^process\.php$ - [L]
To not rewrite requests to that particular file.
Note that you will have to put your file next to Wordpress' index.php for this to work properly.
Change your .htaccess to this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/+folder/process\.php$ [NC]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Try turning off mod_rewrite altogether in your /folder/ directory by creating an htaccess file in there and simply adding this single line:
RewriteEngine On
It will make it so any rules from the parent directory won't be applied. If the weirdness with PHP continues, you may want to check if there aren't any rules in your vhost/server config or that things like Multiviews are turned off (via Options -Multiviews).
Ok so if I took a default file that came with the WordPress install made a copy of it in the cpanel rename it remove the code and than put my code in it.
The file is found and it works. So im thinking the only thing left it could have been was a permissions problem. The permissions i put for the file when i uploaded it was 777. I know NOTHING about file permissions.
And i have been working on this for 5 hours and im done trying to figure out what the problem was it works..and im good with that.

Categories