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

Viewed 35

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 :)

1 Answers

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]
Related