How to overwrite specific URLs to skip folder from path - wordpress

I have WordPress installed in the folder /blog
I need to have a specific page that is part of that WordPress but which should not contain the segment /blog in the URL.
For example:
All my blog pages should be www.domain.com/blog/page-name
My Terms and Conditions page should be www.domain.com/terms-and-conditions
All the solutions I've found were affecting all my /blog/.. pages.
I just need a special condition for one specific page.

You need to internally pass the request to the Wordpress blog page.
This can be done through .htaccess and mod_proxy
your .htaccess file should contain
ProxyPass "/terms-and-conditions" "http://www.example.com/blog/terms-and-conditions"
ProxyPassReverse "/terms-and-conditions" "http://www.example.com/blog/terms-and-conditions"
Proxypass directive internally sent request as a proxy request.
Similar result can be expected from RewriteEngine using [P] flag like
RewriteEngine on
RewriteRule "terms-and-conditions" "http://www.example.com/blog/terms-and-conditions" [P]
Online example for the same is at .htaccess tester

Related

remove a specific part from url with htaccess and redirect

I was using translatepress on my WordPress site so my site URLs were like example.com/en-ae/hair-transplant but now I have removed translatepress so now my URLs are like example.com/hair-transplant but I have submitted URLs for SEO with the en-ae slug. I want that if en-ae is present in any URL then it gets removed automatically and gets redirected to page without en-ae.
For example example.com/en-ae/hair-transplant redirects to example.com/hair-transplant.
You need the rewrite module of Apache: mod_rewrite.
Then in your htaccess this:
RewriteEngine on
RewriteRule ^en-ae/(.*)$ $1
To remove the /en-ae prefix from all requested URLs (to help preserve SEO), you would need to add the following near the top of the root .htaccess file, before the WordPress code block (ie. before the # BEGIN WordPress comment marker):
# Remove "/en-ae/" prefix from all requests
RewriteRule ^en-ae/(.*) /$1 [R=301,L]
You do not need to repeat the RewriteEngine directive, which already occurs later in the file (in the WordPress code block).
The R=301 flag triggers an external "permanent" redirect - without which the URL-prefix is not actually removed. However, you should first test with a 302 (temporary) redirect to avoid potential caching issues.
The slash prefix on the substitution string is necessary to avoid a malformed redirect, if the RewriteBase directive is omitted from the WordPress code block.

Redirect whole domain to a sub-folder on another domain in WP

I have one domain that used to have its own WP installation, say www.aaa.example.
Now the content of this has been included in a different domain in a sub-page, say bbb.example/aaa-subpage/.
Also, the old domain www.aaa.example has a DNS A record pointing to the WP Server of bbb.example.
What I want now is, that all calls go to www.aaa.example/* should be redirected to bbb.example/aaa-subpage/ no matter which sub-page on aaa.example was used. So everything should go to one sub-page in the new domain.
I have tried some 301 redirect plugins but so far no chance... all calls from aaa.example simply go to the top-level page of bbb.example.
To redirect requests to aaa.example/<anything> to bbb.example/aaa-subpage/ you would need to add the following mod_rewrite directives to the top of the root .htaccess file. Crucially, it must go before the WordPress front-controller (ie. before the # BEGIN WordPress comment marker).
# Redirect "aaa.example/<anything>" to "bbb.example/aaa-subpage/"
RewriteCond %{HTTP_HOST} ^(www\.)?aaa\.example [NC]
RewriteRule ^ https://bbb.example/aaa-subpage/ [R=301,L]
You do not need to repeat the RewriteEngine directive that should already appear later in the file (in the WordPress section).
Test first with a 302 (temporary) redirect to avoid caching issues.
You will need to clear your browser cache before testing.
Try this line in the .htaccess:
RedirectMatch ^/$ /aaa-subpage/

How to load wordpress by two URL

I need to wordpress from 2 url, my main wp already run in subdomain wp.domain.com but I can't access from domain.com/wp, I try some change in database and .httaccess file, but I can't run it with 2 url
I need can access both of them :
wp.domain.com
domain.com/wp
WordPress doesn't really support this setup. All posts have saved their URL in the database, if you display the site on the secondary URL all links will still point to the primary URL.
Additionally, displaying the same content on different domains (what this is) is usually penalized by search engines, which is something you usually want to avoid.
You can achieve this by configuring the Apache with mod_proxy and mod_proxy_html to proxy all requests on one domain to the other, rewriting the URLs in the process.
The Apache config for this looks like this:
ProxyPass /wp/ http://wp.domain.com/
ProxyPassReverse /wp/ http://wp.domain.com/
# to rewrite the URLs in the HTML
ProxyHTMLEnable On
ProxyHTMLExtended On
ProxyHTMLURLMap http://wp.domain.com https://domain.com/wp
But I'd recommend to stick to a single URL and configure Apache to redirect all requests on the secondary URL to the primary.
You can do that with a single line in a .htaccess:
RewriteRule ^(.*)$ http://wp.domain.com/$1 [R=301,L]

static to static url rewrite with htaccess with wordpress

I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.

Have WordPress with a different index file for testing

A site I'm designing a website for was built with static HTML files. I'm converting it to WordPress but I need the old site to still function while WordPress is installed in the same directory (e.g. have index.html be the default one and then have WordPress be something like indexNew.php)
So they go to http://domain.com/indexNew.php to see updates to the new website until it's finished.
How would I configure that in the .htaccess file?
You can use a .htaccess with a simply rule to redirect users to index.html except you :
RewriteEngine on
RewriteCond %{REQUEST_URI} !/index.html$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteRule $ /index.html [R=302,L]
Replace 123.123.123.123 by your public ip adress.
You should use your .htaccess to set the default document order:
Tired of having yoursite.com/index.html come up when you go to yoursite.com? Want to change it to be yoursite.com/ILikePizzaSteve.html that comes up instead? No problem!
http://www.javascriptkit.com/howto/htaccess6.shtml
In your case, you won't need to rename the index.php at all - this will do the trick:
DirectoryIndex index.html index.php
Anyone who requests yoursite.com will see the content from index.html. To see the new Wordpress content, just navigate to yoursite.com/index.php

Resources