简体   繁体   中英

Using htaccess to redirect a directory to URL

I want to redirect with .htaccess any of the following:

http://domain.com/folder
http://domain.com/folder/
http://domain.com/folder/index.html
http://domain.com/folder/index.php

to

http://another-domain.com/file.php?var=xyz

I did understand how to rewrite file-to-file or folder-to-folder, but I'm missing how to redirect from a folder to other domain's file URL

Thank you

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^folder(/.*|)$ http://another-domain.com/file.php?var=xyz [L,NC,R=301]

Suggested Reading: Apache mod_rewrite Introduction

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