简体   繁体   中英

Redirect to new url using .htaccess

I'm trying to do a url redirect but the way I have the .htaccess file it doesn't seem to work. Is there a specific place or format I need to use for the redirect?

Below is my .htaccess

# 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>

Redirect 301 /research/report-listings/ http://example.com/research/research-portfolio/

# END WordPress

# BEGIN wtwp_cache
# END wtwp_cache

# BEGIN wtwp_security
# END wtwp_security

You probably don't want to mix mod_alias directives with mod_rewrite directives. Both modules will end up getting applied to the same request and you can end up with some wonky redirects. Best to just use mod_rewrite if you've rules for things like Wordpress.

Note: the order is very important

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^research/report-listings/(.*)$ http://example.com/research/research-portfolio/$1 [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Try putting your Redirect directive inside of a <IfModule mod_alias.c>...</IfModule> block. Then, make sure you have mod_alias.c installed and enabled:

apache2ctl -M  #This is for Linux systems

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