Jeorge Philip
Jeorge Philip

Reputation: 33

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.

Upvotes: 1

Views: 594

Answers (3)

Danielprabhakaran N
Danielprabhakaran N

Reputation: 585

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]

Upvotes: 0

MrWhite
MrWhite

Reputation: 45829

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.

Upvotes: 1

Colby Sargent
Colby Sargent

Reputation: 341

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]

Upvotes: 1

Related Questions