Mask folder in output URL - .htaccess

I have this website, it is my primary domain, however the folder is actually /public_html/annexation.ca. This part is fine, I have an htaccess rule in my public_html folder to deal with that, so that it shows up as annexation.ca and not annexation.ca/annexation.ca.
But I also run a forum off of that website. The problem is that the phpbb software has an auto-direct after logon, logoff and in a couple of other instances. And when it does so it generates a URL like this:
http://annexation.ca/annexation.ca/community
This is not only cosmetically disruptive, but it also impacts the comment section at the bottom of each unique page, where I have Disqus running. What I need is to add a rule to the htaccess file in the root folder that will make these redirects be automatically translated into this again:
http://annexation.ca/community/
Thanks!

Try adding this to your .htaccess
## 301 Redirect Entire Directory
Redirect 301 /annexation.ca/community(.*) /community/$1

You can try this rule on top of other rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+annexation\.ca/(community)([^\s?]+) [NC]
RewriteRule ^ /%1 [L,R=301]

Related

Redirecting a "subfolder" to a new URL; Joomla and .htaccess

This should be simple and I'm not sure why I can't find anything on it...
Simply put
http://www.abcd.org/efg/ (this is a single article in a Joomla site, the rest of the domain needs to stay active, so just the efg part is what I need redirected.)
needs to redirect to
https://www.xyx.com/lmn-op-qrs/
Is this possible in a Joomla site (Joomla Redirect component fails)?
I see plenty for redirecting within a certain domain, and even redirecting the entire domain to a new domain, but nothing about redirecting part of a domain to a new URL.
I'm sure I could pop in a PHP page to the /abcd.org/efg/ directory and redirect it that way, but wondering if it was possible using the .htaccess file.
Thanks!
You may try this rule as your topmost rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+efg[?\s/] [NC]
RewriteRule ^ https://www.xyx.com/lmn-op-qrs/ [L,R=301]
put this rule in top of .htaccess (on http://www.abcd.org/ root directory)
RewriteEngine On
RewriteRule ^efg/$ https://www.xyx.com/lmn-op-qrs/ [R=301,L]

How to redirect a new page (wrong URL) to another page?

I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]

htaccess conditions to redirect variants of directory URL

I've dug around without much luck finding a solution.
I have a WordPress MultiSite using sub-directories as "temp" URLs so clients can review prior to mapping their domain name.
The login for the mapped domains is domain.com/ui which works with a redirect in my htaccess.
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^ui$ /wp-login.php? [R=301,NE,NC,L]
I've also tried this RewriteRule ^ui(.*)$ /wp-login.php [L,R=301]
However, when attempting to login to a temp URL as described above it does not redirect.
I would like a solution that disregards sub-directories and for that matter any permalink structure and redirects /ui to /wp-login.php
Here are a few examples.
http://adopttheweb.com/ui
http://iemajen.com/emajenwebservices/ui
These are both on the same MultiSite blog. The first has been mapped to a domain whereas the second has not and is simply running at a "sub-directory" of the root / parent site.
Put the following code at main directory .htaccess file
RewriteEngine On
RewriteRule ^ui(.*)$ /wp-login.php [L,R=301]
You can also do it by PHP by putting header('Location: path/to/target.php'); at the ui directory index page etc

Problems with htaccess Redirect (Page on one domain to same page on another)

I'm trying to redirect a few pages to a new domain and I have done this before but for some reason I can't get the code to work.
RewriteEngine On
Redirect 301 http://domain.com/page1.html http://domain2.com/page1.html
Can anyone see where I'm going wrong?
In .htaccess file the below code will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Since you say you only want to direct a FEW of your pages and not all of them, you can do:
RewriteEngine On
Redirect /~myaccount/oldpage.html http://www.newsite.com/newpage.html
You specify the path to the page on your current server followed by the URL to redirect to.
OR you can do:
RedirectMatch 301 ^/oldpage\.html$ http://www.newsite.com/newpage.html

URL Rewriting in htaccess

I just rebuilt a site that is currently located at
http://domainnamehere.com/v2
The existing site is located at
http://domainnamehere.com/
I need to set up a redirect so that when someone goes to the old site, it redirects to the new site. I did this on the htaccess file:
Redirect /index.html http://domainnamehere.com/v2/
But this only redirects the homepage, not the rest of the site. I also have another directory that is linked to a separate domain. The above htaccess code redirects http://anotherdomain.com to http://domainnamehere.com/v2. I do not want it to redirect other domain names. THe reason it is redirecting the other domain name is because the files are located in a directory on domainnamehere.com. I hope that makes sense!
If someone goes to http://domainnamehere.com/somethinghere I also want it to redirect to the 404 error page that would be located at http://domainnamehere.com/v2/somethinghere
Basically, I need proper htaccess code for this situation!
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domainnamehere\.com [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/v2/$1 [R=301,L]
Note: jfrobishow technically answered this first, this is just a fix.
Edit: Added optional www.
This should forward {whatever is after you slash} to /v2/{whatever is after you slash}
RewriteCond %{HTTP:Host} ^domainnamehere\.com$
RewriteRule /(.*) domainnamehere\.com/v2/$1
EDIT: this is for isapi rewrite, but the syntax is similar if you are using mod_rewrite.

Resources