Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

redirect - Redirected URL through .htaccess is being redirected to the different location

My .htaccess has the following code :

RewriteRule ^([A-Z]+)$ listings/$1 [R=301]
RewriteRule ^listings/([A-Z]+)/?$ listings_state.php?state=$1  [NC,L]

With this rule I am trying to achieve 301 redirect from spb.com/test_1/XY to spb.com/test_1/listings/XY

However, it is redirecting to spb.com/path/to/test_1/in_server/test_1/listings/CT

and I tried changing .htaccess to as follows:

RewriteRule ^([A-Z]+)$ /listings/$1 [R=301]
RewriteRule ^listings/([A-Z]+)/?$ listings_state.php?state=$1  [NC,L]

RewriteRule ^/([A-Z]+)$ /listings/$1 [R=301]
RewriteRule ^listings/([A-Z]+)/?$ listings_state.php?state=$1  [NC,L]

RewriteRule ^/([A-Z]+)$ /listings/$1 [R=301]
RewriteRule ^/listings/([A-Z]+)/?$ listings_state.php?state=$1  [NC,L]

Nothing seems to work.

Please guide me in this regard. Thank you community :)

question from:https://stackoverflow.com/questions/65880629/redirected-url-through-htaccess-is-being-redirected-to-the-different-location

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

1 Reply

0 votes
by (71.8m points)

Could you please try following, based on your shown samples only. Please make sure you clear your browser cache before testing your URLs

RewriteEngine ON
RewriteRule ^([A-Z]+)/?$ /test_1/listings/$1 [R=301]
RewriteRule ^test_1/listings/([A-Z]+)/?$ listings_state.php?state=$1 [NC,L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...