This is driving me crazy. Its definitely not a cache issue and I've tested the rules at http://htaccess.madewithlove.be/, all work ok. But for some reason I cant get ANY rewriterules to work. I've just added a simple one for testing but if anyone could suggest its maybe wordpress or it is something glaringly obvious in my htaccess?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#rewrites
RewriteRule ^test.html$ http://www.google.co.uk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#redirects
Redirect 301 /success-stories.html /success-stories/
Redirect 301 /introductions-agency-news/ /dating-agency-news/
Redirect 301 /how-do-we-do-it.html /our-service/
Redirect 301 /1.html /
</IfModule>
# END WordPress
In host admin There's a config directive called AllowOverride where you specify which config directives can be overridden by .htaccess. I originally had it set to allowing specific features which included ReWrite. However, I just set it to "All" and obviously, that seems to have done it.
Related
Well I have been using a wordpress site. I want to redirect few urls. for example:
http://example.com/test To http://example.com/final/game
I tried using htaccess but got no success yet.
Try this
# 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]
RedirectMatch 301 /test/ /final/game/
</IfModule>
# END WordPress
If that's a wordpress site then you don't have to waste your time in htaccess, you can simply use different redirect plugin to redirect your url. One of most popular plugin is here
looks like your missing the http:// from your redirect:
Redirect 301 /test/ http://example.com/final/game
Greetings and thank you in advance for your help!
I am trying to redirect certain subfolders from the "category" subfolder, but not all of them. Only about 5 of them.
Example:
http://domain.com/category/fish
http://domain.com/category/lamb
Should redirect to
http://domain.com/tasty/fish
http://domain.com/tasty/lamb
But:
http://domain.com/category/lead-paint
Should not.
What I've tried (in .htaccess):
RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]
I tried both before and after the Wordpress module. I also tried inserting inside the Wordpress module like so:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/category/fish http://example.com/tasty/fish [R=301,L]
RewriteRule ^/category/lamb http://example.com/tasty/lamb [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Changes to .htaccess definately work. Typos generate a 500 response, and I can block by IP address. I'm not sure if Wordpress is overriding my redirects, or if I have a syntax error.
Thank you again.
You need to remove the leading slash just after ^ in the two rules. You also don't need to specify the full domain. The following will do
RewriteRule ^category/fish/?$ /tasty/fish [R=302,L]
(Note the 302 - always test with a temporary redirect, then change to permanent when you're happy.)
Need some help here...
How can i permanently redirect with .htaccess this URL:
mysite.tdl/download/post-name/
to this URL:
mysite.tdl/post-name/#ert_pane1-5
Actually i would like to know how to redirect to this URL too:
mysite.tdl/post-name/
Its WordPress and Download Manager plugin related.
What im trying to do is avoid visitors to reach the package download pages, and be redirected to the actual post pages.
In other words, what i need is to eliminate the /download/ from all URLs.
Thank you.
My actual .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^(.*)/download/(.*) $1/$2 [R=301,L]
</IfModule>
The last line is the one in question. It possibly makes no sense because i was playing on it..
To eliminate the leading /download/
RewriteEngine On
RewriteRule ^download/(.*)$ /$1 [R=301,NC,L]
You can redirect by adding the following to your .htaccess
Redirect 301 /download/post-name/ /post-name/
Redirecting to an anchor (#) is not possible as this is a client side action. You could use Javascript for this.
I have two sites hosted on one server. An old one in a subdirectory and a new one in the root folder.
blog.domain.com in /var/www/ - The Current Site
blog.domain.com/blog in /var/www/blog/ - The Old Site
blog.domain.com/blog is the legacy site that we need to redirect to the new one for various reasons.
I have added a load of 301s to htaccess in the /var/wwww/blog/ folder:
Redirect 301 / http://blog.domain.com
Redirect 301 /subfolder/ http://blog.domain.com
However when I visit htttp://blog.domain.com/blog I get redirected to http://blog.domain.comblog instead of: http://blog.domain.com
Here are the existing HTAccess files:
/var/www/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /domain/
RewriteCond %{HTTP_HOST} ^78\.41\.157\.192$
RewriteRule ^(.*)$ http://blog.domain.co.uk/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
/var/www/blog/.htaccess
# 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
Redirect 301 / http://blog.domain.com
Redirect 301 /subfolder/ http://blog.domain.com
I did not write the htaccess files, any insight into any errors or why adding 301s wouldnt work would be great. I presume its due to a rewrite rule.
The reason this is happening is you're missing a / at the end of your redirect destination. Apache's Redirect simply matches the target URI then appends anything after it to the destination. So:
Redirect 301 / http://blog.domain.com/
Redirect 301 /subfolder/ http://blog.domain.com/
However, since you have wordpress routing rules, you're not going to want to use Redirect at all. Redirect is part of mod_alias, not mod_rewrite, which means when a requested URL matches both modules, they both get applied. So you'll get some weird unanticipated redirection. Try using mod_rewrite only, and add these rules before your wordpress rules:
RewriteRule ^$ http://blog.domain.com/ [L,R=301]
RewriteRule ^subfolder/?$ http://blog.domain.com/ [L,R=301]
I've got a WordPress blog that I'm trying to redirect to a new domain. The 301 redirect works, but it redirects to newdomain.comnew-post instead of newdomain.com/new-post.
Somehow, it's stripping out the slash. Here's the code:
# 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 /old-post/ http://www.newdomain.com/new-post/
What am I missing?
That shouldn't be happening unless there's also a redirect happening at the www.newdomain.com site. You need to make sure that isn't happening.
Another possibility is that maybe mod_alias (the Redirect directive) and mod_rewrite (all the rewrite rules for wordpress) may be interfering with each other. Both get applied to the same URI (when it's /old-post/ in the same URL-file mapping process pipeline. You could try removing the Redirect and stick to mod_rewrite, before wordpress' rules get applied at all. Try something like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^old-post/(.*)$ http://www.newdomain.com/new-post/$1 [L,R=301]
</IfModule>
# 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
This may not be a solution for this exact scenario, but it did solve the problem where the slash character got removed from the URL it was redirecting to.
My code was similar to this:
Redirect 301 / http://www.newdomain.com
Redirect 301 /old-post/ http://www.newdomain.com/new-post/
The solution was to add a slash after the first line:
Redirect 301 / http://www.newdomain.com/
Redirect 301 /old-post/ http://www.newdomain.com/new-post/
One could also try:
Options +FollowSymlinks
RewriteEngine on
RedirectMatch 301 ^/old-post/ http://www.newdomain.com/new-post/