1

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84

3 Answers3

1

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]
Community
  • 1
  • 1
Colby Sargent
  • 341
  • 2
  • 6
  • Another question, would this apply if project.com.ph has multiple subpages like for example, www.project.com.ph/sub/1234, www.project.com.ph/sub/5678, etc.? Or is this a new kind of situation that needs another solution? Thank you! – Jeorge Philip May 18 '17 at 12:32
  • 1
    Also worth noting, if both domains are using the same hosting, you will need to define the full original URL such as in N.Danielprabhakaran's answer. Or, use a rewrite condition before every rule. `RewriteCond %{HTTP_HOST} ^www.project.com$` – Colby Sargent May 18 '17 at 13:03
1

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
0

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]
Danielprabhakaran N
  • 530
  • 1
  • 7
  • 16
  • 1
    This has a few errors... The URL-path matched by the `RewriteRule` _pattern_ does not include the hostname (so this will never match). The _substitution_ is missing the _scheme_, so will be seen as a relative URL-path (which would result in a malformed redirect). The backreference is also missing from the _substitution_ (which I assume you were intending to use since you have a capturing group in the _pattern_ and it's not so useful without it). – MrWhite May 18 '17 at 17:38