mod rewrite - Apache redirect rule for the same url -


i trying write rewritecond , rewriterule following.

if tries access forex.com or forexample.com should both redirect

forexample.com/abcd/xyz/ 

the below rewrite condition works forex.com

rewritecond %{http_host} ^forex\.com [nc] rewriterule ^(.*)$ https://forexample.com/abcd/xyz/ [r,ne] 

but when add rule below goes redirect loop

rewritecond %{http_host} ^forexample\.com [nc] rewriterule ^(.*)$ https://forexample.com/abcd/xyz/ [r,ne] 

any appreciated.

this works because forex.com , forexample.com different domains:

rewriteengine on rewritecond %{http_host} ^forex\.com [nc] rewriterule ^(.*)$ https://forexample.com/abcd/xyz/ [r,ne] 

but in second case, believe issue rule have set redirect on https://forexample.com/ https://forexample.com/abcd/xyz/ if in https://forexample.com/abcd/xyz/:

rewriteengine on rewritecond %{http_host} ^forexample\.com [nc] rewriterule ^(.*)$ https://forexample.com/abcd/xyz/ [r,ne] 

so check request_uri not being abcd/xyz/ , should go:

rewriteengine on rewritecond %{http_host} ^forexample\.com [nc] rewritecond %{request_uri} !^/(abcd/xyz/.*)$ [nc] rewriterule ^(.*)$ https://forexample.com/abcd/xyz/ [l,r,ne] 

but looking over, first http_host rule makes little sense. perhaps want this:

rewriteengine on rewritecond %{request_uri} !^/(abcd/xyz/.*)$ [nc] rewriterule ^(.*)$ https://forexample.com/abcd/xyz/ [l,r,ne] 

a way debug stuff use curl -i command line. command show exact http headers getting based on rule or request. use this; using mamp test environment example:

curl -i http://localhost:8888 

and output me be:

http/1.1 302 found date: sat, 28 jun 2014 02:19:39 gmt server: apache/2.2.23 (unix) mod_ssl/2.2.23 openssl/0.9.8y dav/2 php/5.4.10 location: http://localhost:8888/abcd/xyz/ content-type: text/html; charset=iso-8859-1 

note http/1.1 302 found means it’s temporary redirect , location: http://localhost:8888/abcd/xyz/ indicates rule rewriting call http://localhost:8888 as.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -

jquery - Keeping Kendo Datepicker in min/max range -