简体   繁体   中英

How to use Apache .htaccess to redirect to another folder

I want to redirect from an old folder to a new one.

I want to redirect the http://domain.com/old/ * urls to http://domain.com/new/ *.

I found a question which does exactly that: Redirect folder to another with htaccess

I've tried writing a .htaccess in the document root with only the following code given in the answer to the above question:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/old/(.*)$ /new/$1 [L,NC,R=302] 

I've also enabled mod_rewrite in the httpd.conf file. But I still can't get apache to redirect from the old folder to the new folder.

I've also check the apache error logs, and all I get is the following error:

[error] [client x.x.x.x] File does not exist: <documentroot>/old

I would skip using med_rewrite for this and instead use Redirect , if you want everything requested from old to be directed to new .

<Directory />
    Redirect permanent /old /new
</Directory>

You could skip permanent (Specifies redirect code) depending on your needs. To be able to use a local URL you however need to run Apache >= 2.2.6.

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