So I have Wordpress installed, let's call the domain test.com. The .htaccess that wordpress created in the default directory (the one that is one level above wp-content) 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
I want to add another rule, which if triggered, should case Wordpress to not rewrite. So for instance, suppose I want test.com/nochange to redirect to test.com/script.php, instead of doing the normal Wordpress redirects. Normally the .htaccess for this would be
RewriteRule ^nochange$ ./script.php [NC,L]
But what happens is that Wordpress ends up running anyways, and of course a 404 not found occurs. If I removed the Wordpress .htaccess components, everything works. What do I do to get them to work together?
Ah, I just needed to use the END tag.
Related
I'm trying to create a rewrite rule in htaccess to point a directory at a file, I keep getting 404 errors in return. I should mention, the main site is a wordpress site and I'm trying to redirect one of it's url's internally for a page with a trailing folder to another url.
For instance, this is the url for the wordpress page:
/homes-for-sale-details/4420/217007490/177/
The landing page I'm trying to create within that url is:
/homes-for-sale-details/4420/217007490/177/Fb-landing-page
So I did this:
RewriteRule /homes-for-sale-details/4420/217007490/177/Fb-landing-page/(.*)$ /propertylisting1/index.php?success=$1
No go, I get a 404 error in return. The wordpress page still work, but this won't.
Right now this new rule is placed after wordpress' own rewrite:
RewriteRule . /index.php [L]
I've also tried placing it before wordpress' rewrite and it breaks all my wordpress pages.
I had it in the wrong place, after much testing I found out if I place this rewrite before the RewriteCond statements, it works, and it doesn't brake other Wordpress rewrites.
So the final is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^homes-for-sale-details/4420/217007490/177/Fb-landing-page(.*)$ propertylisting1/index.php?success=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I am new to WordPress, creating the custom taxonomy for location in the my current URL
http://localhost/myproject/locations/us
i am need to change the URL like in that location place rename to my-project
i am trying to change the URL using Rewrite rule in ht-access file
RewriteRule ^my-project/us?$ http://localhost/myproject/locations/us [R=301,NC,L]
but its not working any one help me?
Custom .htaccess in WordPress site can bring unexpected results.
You may instead use WordPress' specific Rewrite API
Edit: if you need to use .htaccess insert your rules before the WordPress' ones.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^my-project/us?$ http://localhost/myproject/locations/us [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This is the final .htaccess code, i tested this solution here and it works correctly.
If this solution didn't solve your case maybe there is a problem elsewhere.
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.
I wish to remove part of a pluggin's URL in Wordpress. I have a standard permalinks setup but have three URLSs with a similar iffy prefix I wish to clean up:
Currently I have
http://domain.com/?pfwk_cats=works
And I require:
http://domain.com/portfolio-works
My current htaccess looks like:
# 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
My solution was to add:
RewriteEngine On
RewriteRule ^portfolio-([^/]*)$ /?pfwk_cats=$1 [L]
But it does not kick in? Any ideas? I assuming the Wordpress Rewrite rules are messing it up? Help much appreciated!
You need to make sure your custom rule is above the #BEGIN WordPress line. The WordPress rewrite rule is a "catch all" so if you put yours below, it will never get there.
Also, don't forget to restart Apache: service httpd graceful
~tommy
I'm trying to redirect a few pages to different pages. This should be simple, but I'm missing something simple, apparently.
I have a wordpress install on a subdomain. Wordpress's generic htaccess is this:
# 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 want to redirect /farm-partners/ to /farm-partners/emilys-produce/. I'm trying to do so using the following code:
RewriteRule ^farm-partners/?$ /farm-partners/emilys-produce/ [L]
However, opening /farm-partners/ doesn't redirect, it just loads that page. What am I missing?
Use the WordPress Redirect plugin and don't mess with the htaccess.
What you are missing in your RewriteRule though, it telling it that you want an external redirect
RewriteRule ^farm-partners/?$ /farm-partners/emilys-produce/ [L,R=301]
If you use a RewriteRule, make sure it is outside the comments that indicate which parts of the file may be edited without any notice (i.e. outside the #comments marking WordPress's section of the file. Similarly if you are using W3 Total Cache or a similar plugin.)
Try this:
RewriteRule farm-partners/$ /farm-partners/emilys-produce/