I found this little trick http://css-tricks.com/snippets/htaccess/301-redirects/ to redirect my old Wordpress domain to my new domain with the path included. I run a test on my local copy and everything works fine. When I log in to the cpanel of the old domain and try it though it gives me some bad results.
Here is the code I used for both my local and live copy ...
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Redirect 301 / http://newsite.com/
Here's what the results look like http://www.cuponsmercado.com.br/lojas/. It looks to be calling the new domain (based on the Google Chrome status at the bottom left) but it just shows the old domain with broken HTML/CSS. Any Ideas?
UPDATE:
I was mistakenly editing the same domain when I thought I was editing both. Both were hosted on the same hosting account but displayed separate cPanel URLs leading to the confusion. There was a chance one .htaccess was conflicting with the other domain as well.
Make this as first rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?cuponsmercado\.com\.br$ [NC]
RewriteRule ^ http://www.cuponsdemercado.com.br%{REQUEST_URI} [L,NE,R=302]
You need to stick with mod_rewrite because a request will get both modules applied (Redirect is mod_alias):
Above your # BEGIN WordPress section add:
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301]
Additionally, you can use mod_alias and get rid of all the old wordpress rules if you are simply moving your site from one server to another.
Related
We have a WordPress site/single app which serves two domain names: example.com and example.es.
In our .htaccess file we have currently have the following rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.es
RewriteRule ^(.*)$ http://www.exmaple.es/$1 [R=permanent,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
We also need to redirect everything from example.com/es/... to example.es/.... I have tried multiple examples that I could find, but none of them worked (ended up in 500 server error and empty log), here are a few of them:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) http://www.example.es/%1 [R=302,NC]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com/es [NC]
RewriteRule ^(.*)$ http://www.example.es/$1 [R=301,NC,L]
All of the new rules were placed inside the <IfModule mod_rewrite.c>
Any help or guidance is much appreciated.
#Domas Hi Domas, the process in your case is to update you site installing some important extension about the domain change.
Changing the preferred domain name alias WordPress uses
If your WordPress site has a domain name alias pointing to it, and you want WordPress to prefer the alias domain name in links that it generates, you can update the domain name in the WordPress dashboard:
Click Settings.
Change the WordPress Address (URL) to the new URL that you want to use.
Change the Site Address (URL) to the same value.
Click Save Changes.
You need WP Super Cache, this extension help you to update automatically the .htaccess and change all the needs as you did on you configuration site.
First install the extension https://support.tigertech.net/move-wordpress#updating-htaccess-wp-jmp
Also if you don't need any extension and you want to do by the hand just redirect like this example as needs :
#the simple redirection
Redirect 301 /es http://www.example.es/
#Redirect from old domain with subdirectory to new domain
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) http://www.example.es%{REQUEST_URI} [R=302,NC]
It depend of you needs i prefer the last one. Regards
I am trying to change the url that is displayed in the address bar from mysite.com/blog/wedding-hair/ to mysite.com/services/wedding-hair/ using .htaccess.
Using answers from:
https://stackoverflow.com/questions/8713319/assigning-different-name-to-existing-folder-in-url-in-htaccess
rewrite a folder name using .htaccess
Replace directory name in url with another name
I added to the .htaccess file. Here is the .htaccess file, I added the last rewrite rule:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^/?$ "http\:\/\/www\.mysite\.com" [R=301]
RewriteRule ^blog/(.*)$ /services/$1 [L]
the non-www redirect works but not the blog-services rewrite. I thought maybe I had the directory names reversed but changing them around doesn't work either. I have tried adding and removing /'s around the directory names in all of the different combinations. I tried adding
RewriteCond %{THE_REQUEST} ^GET\ /blog/
before my RewriteRule. Nothing I Have tried has worked, the displayed url remains mysite.com/blog/wedding-hair/
I am sure this is pretty straight forward for someone but I am unable to get this correct. Any help would be appreciated.
When I was working on this yesterday I didn't think about the fact that the blog directory is a WordPress install. Here is the .htaccess file that is in the blog directory:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
I have tried adding my RewriteRule in this file but still no joy.
The problem here is that RewriteRule ^blog/(.*)$ /services/$1 [L] internally rewrites the URI, so that the browser doesn't know it's happening, this happens entirely on the server's end. If you want the browser to actually load a different URL, you need to use the R flag like you are in your www redirect, though it's only redirecting requests to root. If you want it to redirect everything to include the "www", you want something like this:
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Then to redirect "blog" to "services", just add the R flag (or R=301 if you want the redirect to be permanent).
RewriteRule ^blog/(.*)$ /services/$1 [L,R]
And, if for whatever reason your content isn't actually at /blog/, you need to internally rewrite it back
RewriteCond %{THE_REQUEST} ^GET\ /services/
RewriteRule ^services/(.*)$ /blog/$1 [L]
But this is only if your content is really at /blog/ but you only want to make it appear that it's at /services/.
Actually, in such case, as you have a specific field in Wordpress options to handle the display of a different url, it CAN'T work with .htaccess is the WordPress rules are executed at the end.
And it would be much simpler to use the field "Site Address (URL)" in the General Settings, and enter "mysite.com/services/"
If you don't do that, in spite of your .htaccess, the WP internal rewriting will use you installation repertory
I'm trying to do a permanent redirect with .htaccess, but it isn't working and I have no idea why.
RedirectPermanent / http://www.flunchinvite.fr
I'm trying to do a redirection from : http://www.flunchinvite.com to: http://www.flunchinvite.fr.
Do you have any ideas?
Thanks
edit
I've just did a test to do a redirect to google, and it doesn't work either, whereas when I try to do a redirect with the same code on http://flunchinvite.fr it works. Do you know where that can come from ?
Try something similar to
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^flunchinvite.com[nc]
RewriteRule ^(.*)$ http://www.flunchinvite.cfr/$1 [r=301,nc]
Use Rewrite if it is an option:
http://www.gnc-web-creations.com/301-redirect.htm
Another method we can use is via mod_rewrite. This requires that the
mod_rewrite module is active on your webserver. It usually is and is
done by the system administrators when they installed the webserver.
mod_rewrite is a very powerful URL re-writing engine and we will only
by scratching a hair on its head here.
Again, in your .htaccess file
RewriteEngine ON RewriteRule ^(.*)$ http://mynewdomain.com/$1
[R=301,L]
The above example will re-map your old domain to a new one and issue a
301 status code (permanent redirect). So a request for
http://olddomain.com/foobar.html will go to
http://mynewdomain.com/foobar.html
If you simply want to redirect all requests regardless of the page
requested to the new domain you could use:
RewriteRule /.* http://mynewdomain.com/ [R=301,L]
In this case no matter what file or directory is requested they will
all go to
http://mynewdomain.com/ i.e., http://myolddomain.com/foobar.html
will go to http://mynewdomain.com/
The [R=301,L] means redirect the client and send a 301 status code
(R=301) and make this the last rule (L).
At the end I did a php redirection, I don't know why it's not ok on the htaccess. I'll see that another time. I'm going to bed
Take a look at lines 5 and 6:
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /demo2
RewriteCond %{HTTP_HOST} ^mathpdq\.com
RewriteRule ^(.*)$ http://www.mathpdq.com/demo2/$1 [R=permanent,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I could not get 301 redirects to work so I went with this. basically if the user goes in with mathpdq.com/demo2 it forces a redirect to www.mathpdq.com/demo2.
The stuff below line 6 is just the normal mapping into the php functions.
http://pastie.org/5364605
Ok, so I have to do some work on a client site - and for some reason, they have both the www. subdomain and the empty subdomain in use, with different websites. They do NOT want this.
They want the www. subdomain ONLY (that is, they want the empty subdomain to redirect to www.)
That's how it is set up in Wordpress, supposedly.
Here's my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)(\.htm|\.html)$ /contact [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#php_flag display_errors on
#php_value error_reporting 8191
Can anyone interpret this? (I am not very familiar with .htaccess files - anyone who has any resources on them would be helpful). How do I make it so that anyone going to http://examplesite.com goes to http://www.examplesite.com, for example.
How are there two different websites on the same domain? I'm looking in the public_html folder and there appears to be NO reference to the other site at all - nothing, no files, nada.
To force using www subdomain, you can add this code :
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*) http://www.domain.com/$1 [QSA,L,R=301]
Here is what those line does :
Check the HTTP_HOST, which must be domain.com
Take the current request and add it after www.domain.com/ ($1 represents the request caught)
Use the generated url as a 301 redirection (permanent redirection) with [R=301] tag
Doesn't read next rules if this one is caught, with [L] tag
Forward GET datas, with [QSA] tag.
You must put this code after those two lines :
RewriteEngine On
RewriteBase /
Which set the Rewrite engine on, and define the base url.
Be careful : redirection doesn't forward POST datas. Be sure alwayse use www subdomain in your code (this can easily be done using a centralized base_url).
Have a look here to understand better htaccess files.
I'm using this rewriterule:
RewriteRule ^page/([^/]*)$ http://example.com/page?q=$1 [QSA,L]
If I go to example.com/page/somePage I get redirected to example.com/page?q=somePage
But I don't want a redirection, what I want is the URL to always be example.com/page/somePage
How to do this?
Thank you
I removed http://example.com but it doesn't work, I get Page not Found.
I am using Wordpress for my site, this is my complete .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^page/([^/]+)/?$ page?q=$1 [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Whenever you specify the http:// at the beginning of the path to be rewritten to, Apache will always force a 301 redirect to the new URL, whether the URL is on the same website or not. Simply removing the http://example.com part should fix your problem.
As for the page not found, is there another RewriteRule somewhere that tells just 'page' to be processed as 'page.php' or something of the sort? Do you have your PHP files saved without extensions?
Well then your problem is you definitely need to remove the [L] flag because you're telling Apache not to process any more RewriteRules for that request, so it never looks at the WordPress rewrites because that rule was already executed and Apache was told that should be the final rule. I would recommend leaving the [QSA] in the line though, that would not affect the overall outcome of your script.