Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

apache - Htaccess Redirect directory to another but allow the main folder URL to stay the same

We are currently using the below .htaccess code to redirect /artist/* to /artists/* which works well however, we need the URL /artist/ to remain available and not redirect through to /artists/ is this possible with .htaccess? We'd like to avoid a PHP based redirect if possible.

RewriteRule ^artist/(.*)$ /artists/$1 [R=301,NC,L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you don't want to change URL in your browser means you don't want to redirect and only want to rewrite to different URL then try following(we need to remove R flag from rules. Also this rule considers that you have /artists in your root directory if that's not the case then remove its starting slash in Rule.

RewriteRule ^artist/(.*)/?$ /artists/$1 [NC,L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...