简体   繁体   中英

Redirect Wordpress URL with htaccess

I'm trying to redirect a certain url (actually I have several hundred) to another URL with the following code, but it's not working. The htaccess is in my wordpress root directory, where the wp-content files etc are. What am I doing wrong?

# 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

Options +FollowSymLinks
RewriteEngine On

Redirect http://lifeandhealth.org/qr/049ow34gh9klhg3uqrf2   http://lifeandhealth.org/?p=58
  1. Usually, you put your redirect lines above the WordPress htaccess calls ( #BEGIN WordPress ).
  2. If that doesn't work, I'm uncertain if this will, but try to be as explicit as possible.

    Redirect 301 /qr/049ow34gh9klhg3uqrf2 http://lifeandhealth.org/?p=58

    Change the 301 to 302 if the redirect is temporary.

This isn't exactly WordPress-specific functionality, so look this is a good resource for more advanced redirects.

If that doesn't work, let me know in comments, and I'll try to updated with another (attempted) solution :)

Some other things to keep in mind

  1. If that doesn't work, try redirecting the whole directory with a "/" at the end of the URLs (only do that if it's alright with you, remember it has different functionality)
  2. Make sure there are no blank lines at top of .htaccess file
  3. (more of a "PS:" thing) This is not a solution nor optimal for large number of redirects but this WordPress plugin is fantastic.

Two tweaks:

RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^() index.php [L]
  • Remove the RewriteBase
  • Remove the / in front of index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM