htaccess WordPress and separate directory without filenames - wordpress

On a site I'm working on the main portion of the site is wordpress powered.
I've added another directory completely separate from the wordpress site called employees and I'm having a little issue with the mod_rewrites for the new directory.
obviously wordpress uses this code to make its pretty urls
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress
but I want to add this rule as well and any other necessary rules or conditions so that all of the /name.php files in the employees directory get redirected to just /name
RewriteRule ^employees/(.*)$ employees/$1.php [L,QSA]
The several things I've tried all just cause employees/main to 404 but employees/main.php resolves properly.

Related

htaccess subdirectory and wordpress

I have a php based site with wordpress installed in a subdirectory.
The main php site has urls in the following form
http://www.smokescreencreative.co.uk/nameofpage
which are rewritten using htaccess so they actually access pages like so:
http://www.smokescreencreative.co.uk/index.php?pid=$1
This all works as needed. My problem is with the /blog subdirectory. When in the blog part of the site trying to click on a link back to the main part of the site actually directs to
http://www.smokescreencreative.co.uk/blog/nameofpage
instead of
http://www.smokescreencreative.co.uk/nameofpage
as required and I am getting a 404 error because there is nothing there. I think this must be down to my htaccess files but I can't work out how to make it so the links to the main php page take the form I want but the blog post etc stay in the /blog/nameofpage format.
I did manage to get it so /blog/nameofpage was bringing in the correct written content for the root pages but there was no styling or images and the url was still /blog/nameofpage and I would like it to be just /nameofpage if possible.
I've posted the htaccess code for the root directory and blog subdirectories below. any help with this would be much appreciated.
Thanks in advance
main root htaccess code: (works for the links in the root part of the site)
AddType application/x-httpd-php .php .html .htm
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?pid=$1 [L]
htaccess code for the wordpress subdirectory
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

Modifying wordpress htaccess to forward certain urls to subdirectory

For whatever reason or another I haven't been able to ascertain, my company has decided to go with wordpress for one of their websites. They asked me to build an affiliate application on the same domain, which I did. Everything works great with the exception of this dilemma:
wordpress is installed in the root directory. All pages, videos, sales, etc are made from within wordpress pages.
The affiliate application is in a subdirectory /aff/ and affiliates' pages are found at mydomain.com/aff/index.php?aff=affiliateusername
Affiliates (and their leads) should be able to load their pages simply by typing in www.mydomain.com/affiliateusername but I am struggling to understand how to translate wordpress htaccess rules to do this.
Obviously the best order in which to have this work is for wordpress to first determine if there are any blogs/posts/pages that match the url term FIRST, and if none is found, then to redirect all else to www.mydomain.com/aff/index.php?aff=whatever
Here's what I was finally able to come up with that works for the index page and for the affiliate pages, but does not correctly load any wordpress pages other than index.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(images|wp-admin|wp-content|wp-includes|go|compliance\.html)($|/) - [L]
#RewriteRule ^([^/].*)$ /aff/index.php?aff=$1 [R,L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You can tell I've attempted to exclude certain directories from the rewrite but have not been successful. I've read other advice via Googling, to put the redirect rules ahead of the wordpress block, but there are few issues. When I put this line ahead of the # BEGIN WordPress line, I get an endless redirect loop which keeps going to /aff/index.php?aff=aff/index.php?... etc (this is the same line I use for the same affiliate application on a different, wordpress-free, domain)
#RewriteRule ^([^/].*)$ http://www.mydomain.com/aff/index.php?aff=$1 [L]
I feel like I'm missing something terribly obvious. Should I just be setting up wordpress to redirect all 404's to /aff/index.php?aff=originalrequest? How would I go about doing that?
Thanks in advance.
You are using RewriteRules incorrectly in place of RewriteConds. Adding them in between the WordPress rules is surely breaking your blog as well. Change your .htaccess code to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ /aff/index.php?aff=$1 [R=301,QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
If you want the URL to stay mydomain.com/affiliate remove the [R] and use only [QSA,L]. I've updated the rules above to show how to exclude a path from affiliate redirection. The following
RewriteCond %{REQUEST_URI} !^/blog\b
excludes all URLs pointing to /blog or its sub-directories /blog/sub/dirs from redirection. If there are root-level .php pages present (even if they are few) the exclusion can more easily be handled by changing the rule to
RewriteRule ^([^/.]+)$ /aff/index.php?aff=$1 [R=301,QSA,L]
assuming that a . and a / can never be present in an affiliate name.

wordpress site ignoring sub directory when htaccess present

To begin I did not setup the website I am currently working on, and I am not very familiar with the wordpress setups. I have been called in on their site to add an admin section to this site which uses a Wordpress configuration. If I add a sub-directory, I can access the sub-dir via web just fine. The problem comes when I add a .htaccess to that subdirectory for Auth purposes. When I do this, and try to access the sub-directory, it errors to a 'Page Not Found'.
Can someone please help? I assume it is something with the Wordpress .htaccess file provided below:
# 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
UPDATE
When the .htaccess in the sub directory is blank, I can access the sub-directory via web just fine.
.htaccess (when filled out) in sub directory is below:
AuthType Basic
AuthName "Sphere"
AuthUserFile "/path/to/htpasswd"
require valid-user
I just tested a setup based off of your question. Here's an example of the hierarchy from what I could gather in your post:
public_html/ (all WP install files here)
public_html/admin/ (here I created a new folder similar to your question)
public_html/admin/index.php (test file - just echos a line of text)
public_html/admin/.htaccess (currently blank)
So my .htaccess within the new subdir that's spawned off of the WP root is blank. I'm not sure what kind of auth things would/should be in there. If I access "website/admin/" - the test line echos just fine. I don't see any 404s.
Could you maybe provide a little more detail so I can try to better replicate the issue you're seeing?
Found the solution for my problem elsewhere. Editing the root .htaccess (for wordpress) to match the one below should fix anyone who also encounters this issue:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/NameOf_Directory_ToAllow/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/NameOf_AdditionalDirectory_ToAllow/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Possible permalink or .htaccess error, wordpress

Okay. So I have a site that needs to be live around 8am EST. Everything was going fine, but when I uploaded it to the server my two pages return 404 not found errors. Absolutely everything else on the site is fine.
I have tried several things. I have reset the permalinks several times. I have deleted auto-saved files in the database. I have re-uploaded the database. I have re-uploaded the site. I have set the permission on .htaccess. I have deleted .htaccess and let it rewrite itself. Nothing has worked. Does anyone have any ideas?
The page works when it is set to default, but NOT when it is set to anything else.
Update 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
Based on the .htaccess you can make these changes... although this is the default .htaccess for Wordpress it looks like it has an extra slash in front of index.php for the main redirect line. You'll also want to check to make sure that your Virtual Host Apache directory contains AllowOverride All.
In this example we're telling Apache if the request isn't for index.php then see if it's a real file and a real directory, then if it's not show them the default page. This is similar to the default behavior of Wordpress already.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* index.php [L]
</IfModule>
# END WordPress
There is also a whole Stack Exchange site devoted to Wordpress at wordpress.stackexchange.com.
This is basically the same question:
https://wordpress.stackexchange.com/questions/11149/htaccess-disable-wordpress-rewrite-rules-for-folder-and-its-contents

Wordpress website shows 404 page for folder + images if directly accessed?

Hello guys what can be the reason for this:
I have a folder "wallpapers" not related to my website (Wordpress) in the same web hosting and images inside. If i wanted to access them I would go to website.com/wallpapers/myimage.jpg and it worked!
But I noticed it doesn't work anymore now I see my wordpress site + error 404 inside the website.
I have tried to fix this disabled few plugins etc... but where should I look? What can be the reason? Maybe the htaccess?
Thanks!
Yes, I think your guess on the .htaccess is perfectly correct. If you enable permalinks in Wordpress it automatically creates, or tries to create (depending on permissions) the following .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
The two lines in this that are relevant to you are;
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
What they are basically doing is making sure that every url request gets run through the index.php in the root except any files or directories that actually exist as separate files and directories outwith the Wordpress install (ie your wallpapers directory). So first of all I would make sure that your .htaccess looks like this.
I needed to do the same in the past, and it drove me nuts so if that can help here's what I've done. I had the default .htaccess wordpress created in my wordpress folder when activating the permalinks option, the folloowing :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
for some reason...
I could access http://example.com/phpinfo.php fine,
but http://example.com/myfolder was returning a 404, despite (if I'm correct) the line RewriteCond %{REQUEST_FILENAME} !-d should allow me to show what was into that folder as it's existing and having the correct permissions (user:user chmoded 755)
after having tried everything I could find on the subject, I ended up creating a .htaccess into my folder "/myfolder"
with the unique following line in it :
Options +Indexes
And I finally got http://example.com/myfolder to answer the response 200 OK
I suppose this is not the best ever solution but it's the only one that worked for me and as I just need this to work for one or two folders, it did not need to be more adaptive / flexible

Resources