Removing Wordpress directory name from certain URLs using .htaccess - wordpress

So I have one Wordpress install in a sub-directory. (www.mysite.com/wp/)
What I need is for certain pages to remove the WP directory name from the URL.
so 'www.mysite.com/wp/careers' needs to be -> 'www.mysite.com/careers'
I have an .htaccess in the root directory and in the wp directory. I've gotten some of my rules to work when permalinks are disabled in WP, but when those are enabled (which they need to be) the WP .htaccess overrides any rules I have in the root.
Is there any way to have 2 htaccess co-exist in this manner? Sorry I haven't messed with wordpress and apache very much.
Any input is greatly appreciated.
**So I finally got this working, it was just a matter of like you said formatting redirect URL so wordpress likes it.
So in my root htaccess file : for this url mysite.com/careers
RewriteRule ^careers/?$ wp/index.php?pagename=careers [L]
And voila and it started working just fine.

Yes, you can have rules in both htaccess files but it's going to be tricky as wordpress has specific ways that it will expect URLs to look.
In the wordpress htaccess file, above any wordpress related rules, add:
RewriteCond %{THE_REQUEST} \ /+wp/careers
RewriteRule ^ /careers [L,R]
then in the htaccess file in the document root add:
RewriteRule ^careers$ /wp/careers [L]
But again, depending on what wordpress expects the "careers" URL to look like, this may not solve your problem.

Related

wordpress home page use from different directory

I have wordpress installed on my root folder directory files are like public_html/wp-admin, public_html/wp-content etc..
I want it when my site "www.example.com" is visited it will read another folder in the subdirectory eg (public_html/showhomepage)
where showhomepage has a static index.html with css, images etc
Is this possible?
In your wordpress/index.php:
header('Location: showhomepage');
Or you can set up a rewrite rule in your .htaccess file:
RewriteCond %{DOCUMENT_ROOT}/index.php !-f
RewriteRule . /showhomepage [L]
Or something along those lines. Apache has good on mod_rewrite and there's plenty of supporting sites to make some of the explanations more clear.
I may be mistaken but, that redirects requests to your site to showhomepage. I'm not an expert at rewrite rules but I think you can suppress the path with REQUEST_FILENAME in your rewrite conditions.

Wordpress Install with other software installed in a subdirectory

I'm having an issue that I think can be solved with .htaccess, however, I'm not sure exactly how, htaccess rules have never been a strong point for me.
I have a domain with WHMCS installed on it, in a subdirectory, like this:
/websites/manage/
the /websites/ directory is otherwise empty.
Now, I have installed WordPress on the root of the domain, and I want to use the /websites/ location in the WordPress permalink structure, as I want to build a WordPress page that describes the products and services available there, and use it as a gateway to the WHMCS portal located beneath it.
I've tried searching for an answer to this problem, but I keep turning up tons of results about installing wordpress in a subdirectory, and nothing else.
Thanks for your help.
EDIT:
I should have mentioned:
Currently, I get the WHMCS portal when I go to /websites/manage/, which is fine.
However, my problem is that when I go /websites/ I get a directory listing instead of my WordPress page.
I solved this by adding the following to the beginning .htaccess file, before the WordPress section:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/websites/$
RewriteRule . /index.php
</IfModule>
This redirects the /websites/ directory to the /index.php file which WordPress can then use to find its matching page. It still allows the sub directory /websites/manage/ to be controlled by the WHMCS software residing there.

how to add timthumb rewrite after theme set up

here is my htaccess rewrite rule for my theme's timthumb script.
RewriteRule ^pics/([0-9]+)x([0-9]+)x([0-9]+)x([0-9]+)/(.*)$ wp-content/themes/mt_movie/crop.php?src=$5&h=$1&w=$2&q=$3&zc=$4 [L]
I found a text about rewrite rules, on wp codes docs pages.
But i don't know what should i do / or how can i use my RewriteRule via this functions.
Here is the doc link : http://codex.wordpress.org/Rewrite_API/add_rewrite_rule
Actually i want to add this rule after when my theme activated on my customer's web site?
Could anyone help me about this.
Thanks.
This is an Apache rewrite rule. It should go in the .htaccess file in the wordpress directory on your server, assuming that your web server is apache.

url rewrite using htaccess to force load index.php

I'm trying to make a user-friendly author page url for my wp site. Currently what I have done is I have created a folder by name author under my root theme folder and I have put my author page mark-up file(index.php) inside this folder.
I also have a plugin 'Easy url rewrite' which I'm using to make www.sitename.com/author request to load <theme dir>/author/index.php file. And it is working fine.
Now I want any www.sitename.com/author/<anyname> also to load my index.php file.
Can I achieve this using .htaccess rules? Does .htaccess rule conflict with my url-rewrite plugin?(which one will be executed first?) Can I achieve this whole thing using only .htaccess rules(ie., without the use of plugin rewrite) If so, What rules do I need to write in .htaccess file?
Thanks! Greatly appreciate your help.
Does .htaccess rule conflict with my url-rewrite plugin
yes, probably.
which one will be executed first?
The htaccess rules get executed first, but that's part of how wordpress works. There are rules that essentially send everything to wordpress' controller and then wordpress handles it from there.
Can I achieve this whole thing using only .htaccess rules
It depends. Is your page generated by wordpress or is it just a page by itself separate from wordpress? If it's the former, you're going to need to work on some more easy url rewrite rules, if the author page is separate from wordpress then you can do this entirely with htaccess.
If that's the case, I'd guess the rules would look something like:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^author/(.*)$ /themedir/author/index.php [L]
Those rules need to be before any wordpress rules that you have in the htaccess file in your document root.

.htaccess - Rewrite a request to one directory before the request is handled by that directory?

I'm trying to exclude all BUT one directory from a rewrite rule. I want the request to be handled by the index.php file in the root directory which will then include the subdirectory's index.php file as part of a script after wrapping it with it's own code.
This is a really strange problem, since I'm trying to wrap Drupal within a Wordpress installation so that the existing site structure can stay put, and I can use a custom template to wrap the drupal output in a slightly customized wordpress theme.
If anybody has any idea how I can do this, I would be very very thankful.
htaccess files seem like arcane arts. Nobody seems to really get them that well, and I am no exception.
RewriteEngine on
RewriteCond $1 !^(drupal_directory|robots\.txt) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
The ! will exclude drupal_directory and robots.txt etc...

Resources