I had the page name as the-book.html, but now i changed the page name to about-the-book. I have used the rewrite rule as
`Redirect 301 /the-book.html http://www.xxx.com/about-the-book.html`
but it is not working.
my full .htaccess code is here
RewriteRule ^/the-book.html$ http://www.xxx.com/about-the-book.html [R=301]
# 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
RewriteRule ^the-book.html$ http://www.example.com/about-the-book.html [R=301]
Not sure about the Redirect directive, but
RewriteRule ^the-book.html$ http://www.xxx.com/about-the-book.html [R=301]
should work nicely.
Edit:
Removed the leading / in the match part.
Related
I have a scenario where I need to redirect all URLs or wordpress without trailing post id using .htaccess
Example:
https://example.com/chapter/subject-origin-chapter/1223 to https://example.com/chapter/subject-origin-chapter
and
https://example.com/subject/subject-physics/38957 to https://example.com/subject/subject-physics
Other solutions are also welcome.
Current .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I found a solution as:
RewriteRule ^chapter/([a-zA-Z0-9-]+)/(\d+)$ /chapter/$1 [L, R=301]
RewriteRule ^subject/([a-zA-Z0-9-]+)/(\d+)$ /subject/$1 [L, R=301]
I am trying to redirect using a .htaccess file and it's not working. The syntax seems to be correct. Does any one have any ideas what is incorrect?
# 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 /www.easycovertarp.com/ http://www.aeroindustries.com/products/easy-cover/
Insert this rule just below RewriteBase line:
RewriteCond %{HTTP_HOST} =local.aero.com
RewriteRule ^/?$ http://www.aeroindustries.com/products/easy-cover/ [L,R=301]
Ordering is important in mod_rewrite rules so this rule must be placed above shown WP rules.
I am looking to write 301 redirects for a site. I would like the redirect to go from http://www.ehlconsulting.com/our-services-basic-services/ to http://www.ehlconsulitng.com/services/.
My .htaccess file is as follow
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ehlconsulting.com
RewriteRule (.*) http://www.ehlconsulting.com/$1 [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
Redirect 301 /our-services-basic-services/ http://www.ehlconsulting.com/services/
When you go to the old URL it doens't redirect. Instead it shows "Bots get the naked version"
You probably don't want to use Redirect and want to move the actual redirect above your wordpress rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ehlconsulting.com
RewriteRule (.*) http://www.ehlconsulting.com/$1 [R=301,L]
RewriteRule ^our-services-basic-services/(.*)$ http://www.ehlconsulting.com/services/$1 [L,R=301]
# 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
The "Bots get the naked version" thing doesn't have to do with your rules, it's probably WPEngine or something that's doing that by default, and you might be able to override that by using a ErrorDocument 404 in your htaccess file. The problem with using a Redirect along with wordpress' RewriteRule's is that they conflict with each other.
I have the following in my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /entertainment/
RewriteCond %{THE_REQUEST} (\s|%20)
RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ $1-$2$3 [N,DPI]
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301,DPI]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /entertainment/index.php [L]
</IfModule>
# END WordPress
The problem is that domain.com/entertainment/testing 1/ redirects to domain.com/testing-1 instead of domain.com/entertainment/testing-1/. How do I fix this?
The [DPI] flag used means discard path info. Hence, the rewrite base isn't taking effect. Either use
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301]
Or, append the directory name to the rewrite rule as
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /entertainment/$1-$2 [L,R=301,DPI]
I have a wp page with the url, http://mydomain.com/home/ . I would like redirect it to http://mydomain.com/ using htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/$ index.php [L] #This is my attempt to redirect; not working.
RewriteRule . /index.php [L]
</IfModule>
Write rule outside the default wp htaccess rules set. Try below:
RewriteRule ^home/(.*) http://mydomain.com/$ [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Just set the Home page to your front page in wordpress reading settings. That should do it without apache mod_rewrite
Use 301 redirect, is permanent and is good for SEO
RedirectMatch 301 ^/home($|/.*) $1
Tested this on my localhost :)
/home
/home/
/home/?blahblah
this all redirects to / preserving the right portion query strings