Wordpress URL rewrite subfolder to another subfolder - wordpress

I have been trying for several hours now to do a simple url rewrite on a fresh wordpress install and not having any luck.
Suppose my website has a page with some content
-example.com/samplepage
If someone types in the browser example.com/au/samplepage,
I want to rewrite the URL so it loads example.com/samplepage but keeping example.com/au/samplepage in the browser URL
I have tried ^ax/?(.*)$ /global/$1 [L] in my htaccess but no luck. I feel as though wordpress is over-writing something as it just displays the 404 error page.
I can however do a redirect from example.com/au/samplepage to example.com/samplepage where the browser URL example.com/samplepage, however if I want to keep the original URL, it seems impossible.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^au/?(.*)$ /$1 [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help will be greatly appreciated
I wouldn't think this would need mod_proxy? I have also tried the [PT] flag but no luck.

Related

301 Redirect all page and post urls from .html to /

I have a current site which got all URLS end with .html.
I created a new site and the URLS are pretty much the same but without .html.
I've been trying codes found here in my .htaccess file and most seem to cause Internal Server Error.
http://example.com/page1.html to http://example.com/page1/
http://example.com/page1/page2.html to http://example.com/page1/page2/
My current htacces file code 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
You can install Simple 301 Redirect plugin and try to setting like image below. Just tested on my live site and it's running exactly what you want.
Remember you checked Use wildcards? checkbox too.

HTAccess ModRewrite not working for directory to file

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

.htaccess 301 redirects in wordpress for select subfolders in a subfolder

Greetings and thank you in advance for your help!
I am trying to redirect certain subfolders from the "category" subfolder, but not all of them. Only about 5 of them.
Example:
http://domain.com/category/fish
http://domain.com/category/lamb
Should redirect to
http://domain.com/tasty/fish
http://domain.com/tasty/lamb
But:
http://domain.com/category/lead-paint
Should not.
What I've tried (in .htaccess):
RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]
I tried both before and after the Wordpress module. I also tried inserting inside the Wordpress module like so:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Changes to .htaccess definately work. Typos generate a 500 response, and I can block by IP address. I'm not sure if Wordpress is overriding my redirects, or if I have a syntax error.
Thank you again.
You need to remove the leading slash just after ^ in the two rules. You also don't need to specify the full domain. The following will do
RewriteRule ^category/fish/?$ /tasty/fish [R=302,L]
(Note the 302 - always test with a temporary redirect, then change to permanent when you're happy.)

Redirect loop when combining htaccess with permalink wordpress explanation

I have a problem redirecting links using htaccess rewrite. Originally I had only the Rewrite Rule part without the WordPress code underneath and it was working fine. Now, after I tried to add a permalink using Wordpress, the link is giving me a redirect loop problem.
Essentially what I want to do is allow the viewers to go straight to 'www.example.com/blog' when they type 'www.example.com'
I think I am missing something because I thought that the rewriteRule would stop the moment
RewriteRule ^$ /blog [R=301,L]
is processed because of the [L] flag and then other RewriteRules would not be looked at. Can someone help me understand how the server actually go through the steps of the code below?
RewriteEngine on
RewriteRule ^$ /blog [R=301,L]
# 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
You need to put the line:
RewriteRule ^$ /blog [R=301,L]
In the htaccess file in your document root, not in the /blog directory.

Wordpress htaccess redirect issue

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/

Resources