Currently I can rewrite a URL like this
RewriteRule ^pageOne$ /pageOne.php
I would like to do a Redirect to another domain not a rewrite to the current
So in the example below users who click on pageOne get redirected to the other URL
RewriteRule ^www.example.com/pageOne$ www.newexample.com/pageOne.php
EDITED
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^blog.example.co.uk$
RewriteRule ^a-blog-post$ http://www.newexample.com/reviced-blog-post.html [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
That rule will be like this:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^pageOne/?$ http://www.newexample.com/pageOne.php [L,R=301,NC]
Related
In my .htaccess file I have the below code. If I had to redirect all these domains to a single page on a new domain is there a short-hand way to write the redirect?
www.olddomain.com, olddomain.com
www.olddomain2.com, olddomain2.com
www.olddomain3.com, olddomain3.com
Do I need to keep redeclaring the RewriteEngine On statement?
Finally, for the new domain url, how do you specify either http,https? Does the ^ handle anything before the domain name as a wild card, '^newdomain.com'
# 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
# REDIRECTS
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/some-page-url/$1 [L,R=301,NC]
I'm trying to have the following URL redirect to a new structure:
Before: http://example.com/profile/?name=some-one
After: http://example.com/profile/some-one/
The some-name will change depending on the user's account, so I want that part to be dynamic. This is what I have for my .htaccess
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{QUERY_STRING} (^|&)name=(.*)
RewriteRule ^profile/$ /profile/$1/? [L,R=301]
According to this online htaccess tester, this would be the result:
http://example.com/profile//
Any help on clarifying why it's not carrying over the dynamic some-name? If it matters, this is for a WordPress site which already has the following:
# 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
Try
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{QUERY_STRING} (^|&)name=(.*)
RewriteRule ^(.*)$ /profile/%2/? [R=301,L]
Use % for vars captured in RewriteCond's
I'm trying to do a .ca to .com domain 301 redirect however no matter what I do it doesn't work. I've not actually done this before so I've serached about it but the code I have in doesn't work? As my .ca domain just goes to a "not found" page. Shouldn't be be redirecting to my .com domain
Here is the code I have in my .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.ca [NC,OR]
RewriteCond %{HTTP_HOST} ^example.ca [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]
I have a bunch of rules form W3TC and this snippet which I'm assuming has to do with a landing page plugin we have on the site:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)/([0-9]+)/ /go/$1?lp-variation-id=$2 [QSA,L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteRule ^landing-page=([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Advice is great! Thanks!
I have created a new Wordpress site that will replace a multi-domain website.
Server redirections has been done on different domains to point all of them to the same path.
I need do redirect pages based on the parent domain and also, redirect specific domain pages to new specific domain pages .
For example, when "www.mysite-example.com.au/contact" is requested it should redirect to "mysite.com.au/contact-us" and also "www.mysite-example.com.au/contact/form" should redirect to "mysite-example.com.au/request-contact-form"
Here is my current htaccess where I'm doing global redirection
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.abilitypeople.com$ [NC]
RewriteRule ^(.*)$ http://abilitypeople.co.uk/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.abilitypeople.co.uk$ [NC]
RewriteRule ^(.*)$ http://abilitypeople.co.uk/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.abilitypeople.com.au$ [NC]
RewriteRule ^(.*)$ http://abilitypeople.com.au/ [R=301,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
Does any one know how to create these redirections on the same htacces
"www.mysite-example.com.au/contact" -> "mysite.com.au/contact-us"
"www.mysite-example.com.au/contact/form" -> "mysite-example.com.au/request-contact-form"
"www.mysite-example.co.uk/contact" -> "mysite.co.uk/contact-us"
"www.mysite-example.co.uk/contact/form" -> "mysite-example.co.uk/request-contact-form"
By the way, thanks to anubhava for his help
You can have your rules like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?abilitypeople\.com$ [NC]
RewriteRule ^ http://abilitypeople.co.uk%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^www\.(abilitypeople\.(?:co\.uk|com\.au))$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^contact/?$ contact.php [L,QSA]
Trying to set 301 redirect in .htaccess file and here is what i am trying to do
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L]
I am testing this on my local machine using WAMPP server.Though when i hit http://localhost/wordpress/ i am getting redirected to http://www.mysite.com/wordpress/ but for other URL i am not getting redirected at all.for e.g
I have this URL in my local machine http://localhost/wordpress/2010/11/shadows/ and this at the server http://www.mysite.com/wordpress/2010/11/shadows/ but when i hit this URL i am not getting redirected to respected URL on the live server ,but i am being showed same page from local machine.
Working:
http://localhost/wordpress/
=> Redirected to:
http://www.mysite.com/wordpress/
Not working
http://localhost/wordpress/2010/11/shadows/
=> Redirected to:
http://www.mysite.com/wordpress/2010/11/shadows/
As clear from URL, I am trying to do this in Wordpress.
Here is complete .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L]
Can any one tell me whats wrong with the redirection entry? Thanks in advance
Update
I have even tried this option
Options +FollowSymLinks
RewriteEngine on
RewriteBase /wordpress/
RewriteRule ^(.*)$ http://www.mysite.com/wordpress/$1 [L,R=301]
Did not worked.
Always you first then the others (talking about RewriteRules only, man! :D ) (and you've forgotten the QSA directive).
So here's the "clean" version of your RewriteRule:
<IfModule mod_rewrite.c>
RewriteEngine On
# BEGIN My Own rewrite rules
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*) http://www.mysite.com/wordpress/$1 [QSA,R=301,L]
# END My Own rewrite rules
# BEGIN WordPress
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
# END WordPress
</IfModule>
If it's in a .htaccess file then try without the / like this:
<IfModule mod_rewrite.c>
RewriteEngine On
# BEGIN My Own rewrite rules
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
# Without the / after wordpress:
RewriteRule (.*) http://www.mysite.com/wordpress$1 [QSA,R=301,L]
# END My Own rewrite rules
# BEGIN WordPress
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
# END WordPress
</IfModule>
By the way this is the first time in many years that a find an "under construction" page nice!
Please tell me if it works.
%{HTTP_HOST] will contain something like localhost or www.thecolorsofmysoul.com. So your conditions will never match.
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
and the redirecting to the external domain will never fire.
Also the first two rule act in consort to map any non-file/directory to index.php. http://localhost/wordpress/ has a regexp match string of "" so will fail the pattern "." and will fail through and will redirect with your "update". Try
Options +FollowSymLinks
RewriteEngine on
RewriteBase /wordpress/
RewriteCond %{HTTP_HOST} =localhost
RewriteRule ^.* http://www.thecolorsofmysoul.com/wordpress/$0 [L,R=301]
BTW with this base this should be in DOCROOT/.htaccess. The corresponding Wordpress rules (which shouldn't be above this redirect) are
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!index\.php$) index.php [L]
You don't need to repeat the base in the target and the negative lookahead assertion removes the need for the first index.php rule.