I've been looking to find a solution for this problem but I believe I'm not asking the right question so I'll explain it in detail here.
I built a new HTML site and I want to redirect the old domain which was a PHP site to the new domain which is going to be a HTML site. URL structure is same but file format is changed.
I need a .htaccess code that redirects all pages from old domain to pages of the new domain.
for example: oldsite.com/contact.php ===> newsite.com/contact.html
any ideas?
thanks
Try adding this rule to the htaccess file in your oldsite.com's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} oldsite\.com$ [NC]
RewriteRule ^(.*)\.php$ http://newsite.com/$1.html [L,R=301]
Related
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]
Recently I built a site with php but the old site they had was all in HTML. So now I dont know what what is the best way to redirect all those old links to the new site (maybe redirect all links with HTML to the main domain) with .htaccess, what is the best practice ?
Here is what I have tried but the site says to many redirect loops:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.de
RewriteRule (.*) http://www.example.de/$1 [R=301,L]
RedirectMatch "\.html$" http://www.example.de
So first we redirect all non-www links to www, then when the page has .html in the end to redirect to the main site.
Option 1: Redirect all old .htmllink to new sites's /
RewriteEngine On
RewriteRule \.html$ / [L,R=301,NC]
Option 2: If .html file name and .php file names are same then redirect all old .htmllink to new sites's .php /
RewriteEngine On
RewriteRule ^(.+?)\.html$ /$1.php [L,R=301,NC]
Depends, if it is a new domain you need to point to, add a domain pointer from the old domain to point towards the new domain, this will resolve in the server handling the redirect, this is the most efficient way.
This will work better than .htaccess because it's faster and does not cause a second initial page load (due to redirect).
If you don't have access to the server or domainpointers you could make the index.html an index.php file if php runs on the old server, from here simply put:
header('Location: http://www.newdomain.com/');
This will automatically redirect.
Hope this helped you.
‐ Sid
So I've been looking but so far can;t find something that I'm looking for exactly. Looked at this article How can I forward ALL pages to the same exact page on a different domain using .htaccess? but it seems to only redirect my home page.
Currently, I'm using WordPress and I need to be able to forward all pages to a new domain. For example, domain1.com/about-us needs to go to domain2.com/about-us. But I have about 50 pages this needs to work on. I would like to see if there is a 1-5 line code to use for this to work.
Thanks!
Try putting this (above any wordpress rules) in the htaccess file in domain1.com's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} domain1.com [NC]
RewriteRule ^(.*)$ http://domain2.com/$1 [L,R=301]
If your 2 domains are one different webservers, or don't share a common document root, you can just use mod_alias, adding this to the htaccess file in domain1.com's document root:
Redirect 301 / http://domain2.com/
Could someone tell me how to rewrite this URL. I have looked at a lot of questions on stackoverflow but they seem to be missing my answer.
RewriteEngine On
That is what I have... its a bit poor.
I need to rewrite url's if they do not point to a directory.
I need to do this...
any.domain.com/pages/some-page-slug/login
To be rewritten to the correct url of...
any.domain.com/pages/login.php?page=32
Does anyone have any ideas on how this can be achieved?
1) Rewriting product.php?id=12 to product-12.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
2) Rewriting product.php?id=12 to product/ipod-nano/12.html
SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.
RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
3) Redirecting non www URL to www URL
If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
5) Redirecting the domain to a new subfolder of inside public_html.
Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1
TO do this you need to write a front controller.
See here, here, here, and here.
Alternatively in Apache you can rewrite this
any.domain.com/pages/32/login
or this:
any.domain.com/32/login
or even this:
any.domain.com/some-slug/32/login
to this:
any.domain.com/pages/login.php?page=32
One way or another to do this with only apache you need to supply the page id in some fashion. Keep in mind even with format any.domain.com/some-slug/32/login the content of the slug is irrelevant and won't necessarily link to the correct page. Which I imagine is undesirable and bad for SEO.
Another alternative is using RewriteMap. But this will be tricky and require reloading apache configurations whenever a page/slug is created/edit.
I understand that pages and login are static in this case and some-page-slug is changing. And you always want to redirect to static page /pages/login.php?page=32
So this is how to do it:
1) Rewrite
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32
or 2) Redirect Pernament
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=301,L]
or 3) Redirect Temporary
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=302,L]
Here is great article about htaccess trics
http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
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.