apache - Htaccess redirecting not rewriting -


i have 2 domains - example.com , example.co. both domains on same web hosting package , both document roots 'public_html'

i want rewrite string after example.co (e.g. example.co/abc123) https://www.example.com/page.php?url=text-here

here htaccess, seems redirecting instead of rewriting.

rewritecond %{http_host} ^(www\.)?example\.co$ [nc] rewriterule ^(.*)$ https://www.example.com/page.php?code=$1 

from question along comments, seems want redirect request example.co , without www page.php?code=anything after, if right try:

# match example.co , without www rewritecond %{http_host} ^(www\.)?example\.co$ [nc] # make sure don't redirect page.php rewritecond %{request_filename} !page\.php # internally redirect received page.php query string code rewriterule ^(.*)$ /page.php?code=$1 [l] 

this internally redirect user still see domain example.co.

given still want use https, in case not can further use this, instead of above rule:

# if not start www redirect www.domain # make sure domain.co enclosed parenthesis below rewritecond %{http_host} !^www\.(example\.co)$ [nc] # use make sure redirecting right domain # in case of multiple domains rewritecond %{http_host} example\.co$ [nc] rewriterule ^ http://%1%{request_uri} [l,r=301]  # if https not being used force https rewritecond %{https} !=on # because want force domain rewritecond %{http_host} ^example\.co$ [nc] rewriterule ^ https://%{http_host}%{request_uri} [l,r=301]  # , internal redirect # match example.co, don't need match www anymore rewritecond %{http_host} ^example\.co$ [nc] # here check if file on url page.php # don't want redirect or may fall loop rewritecond %{request_filename} !page\.php # internally redirect received page.php query string code rewriterule ^(.*)$ /page.php?code=$1 [l] 

otherwise rule have should work fine:

rewritecond %{http_host} ^(www\.)?example\.co$ [nc] rewriterule ^(.*)$ https://www.example.com/page.php?code=$1 [r=302,l] 

when domain different or protocol different yield redirect or not that's how works.

so if try redirect domain domain b internally not work.

same applies sub domain main domain or other domains or other sub domains.

to put simple can redirect internally from domain in question itself.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -