I want to edit Wordpress 3.5 .htaccess file to define some url redirect rules eg:
Redirect http://localhost/my_site/blog/cat/hello-world to http://localhost/my_site/cat/hello-world
I tried
Redirect 301 /localhost/my_site/blog/cat/hello-world/ http://localhost/my_site/hello-world/
and also
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my_site/
Redirect 301 http://localhost/my_site/blog/cat/hello-world/ http://localhost/my_site/cat/hello-world/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my_site/index.php [L]
</IfModule>
but browser says
Page Not Found
This is somewhat embarrassing, isn’t it?
any idea.. how can i do this..?
You don't want to use Redirect in conjunction with mod_rewrite, just stick with mod_rewrite. Replace the Redirect with:
RewriteRule ^my_site/blog/cat/hello-world/ /my_site/cat/hello-world/ [L,R=301]
Related
We had several domains parked on top of our main website. This was a normal HTML website and we used the following redirect so that the domain would 301 redirect to the proper url to avoid getting dinged by Google.
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
So the above htaccess code just rewrites the url to www.ourmainsiteurl.com, which is what we want.
Now here's the problem... we installed Wordpress and it has the following default htaccess 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
I tried to add my redirect code in but that broke Wordpress. Can anyone tell me what I need to use to make this work?
Simply put I want all the parked domains (ie: parkedurl1.com, parkedurl2.com, etc) to be redirected to www.ourmainsiteurl.com with the htaccess file.
Make sure the redirect is before any wordpress rules:
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$ [NC]
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,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
If it's still not working, check to see if wordpress has something turned on that is redirecting, or adding/removing the "www" from the hostname.
this seems like kind of a rare situation, as i haven't been able to find a thread on it so far.
i have a wordpress site built in a subdirectory (i.e. example.com/subdir/ is the homepage).
i am now building a new site on the same domain to replace example.com/subdir/ and it will be located at example.com, in the root directory.
i need to 301 redirect all pages under example.com/subdir/folder1/ to one page at example.com/newfolder/
i don't have a lot of htaccess experience, but i expected the following htaccess file to work (i placed it in the example.com/subdir/ directory). however, it is still letting me visit example.com/subdir/folder1/ and all pages underneath it without redirecting me to example.com/newfolder/
what am i doing wrong?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]
RedirectMatch 301 ^/folder1(.*)$ http://example.com/newfolder/
</IfModule>
i also tried it with the Redirect 301 command instead of RedirectMatch 301, and no dice.
Have 301 rules before other WP rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteRule ^folder1(.*)$ http://example.com/newfolder/ [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]
</IfModule>
For IP canonicalization, I'm told I need to redirect the IP address of the site to the domain name. I'm running a standard WordPress install that already comes with it's own .htaccess file. I modified it below by adding the "Redirect" line:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 http://12.34.56.789 http://www.domainname.com
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
However, it's not working. Anyone know what is wrong?
Thanks!
You generally don't want to mix Redirect (mod_alias) with RewriteRule (mod_rewrite) because they both get applied to the same URI and will clobber each others changes sometimes. Just stick with mod_rewrite because you have wordpress rules that already use it.
Replace the
Redirect 301 http://12.34.56.789 http://www.domainname.com
with:
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
Jon Lin's answer worked for me but I had to use
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
instead of
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [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/
I switched my website from MODx to Wordpress to a different platform so now I have to make a 301 redirect.
All I need to do is to 301 Redirect http://www.domain.com/page-name.html to http://www.domain.com/page-name/.
What lines should I add to my Wordpress .htaccess file?
.htaccess file
# 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
For just one page, try:
Redirect 301 /page-name.html /page-name/
For everything ending with html, try:
RedirectMatch 301 ^/([^.]+)\.html$ /$1/
Be aware the full URL does not work, only use the relative URL