PHP Version 5.4.16
Apache Loaded modules
core mod_so http_core mod_access_compat mod_actions mod_alias mod_allowmethods mod_auth_basic mod_auth_digest mod_authn_anon mod_authn_core mod_authn_dbd mod_authn_dbm mod_authn_file mod_authn_socache mod_authz_core mod_authz_dbd mod_authz_dbm mod_authz_groupfile mod_authz_host mod_authz_owner mod_authz_user mod_autoindex mod_cache mod_cache_disk mod_data mod_dbd mod_deflate mod_dir mod_dumpio mod_echo mod_env mod_expires mod_ext_filter mod_filter mod_headers mod_include mod_info mod_log_config mod_logio mod_mime_magic mod_mime mod_negotiation mod_remoteip mod_reqtimeout mod_rewrite mod_setenvif mod_slotmem_plain mod_slotmem_shm mod_socache_dbm mod_socache_memcache mod_socache_shmcb mod_status mod_substitute mod_suexec mod_unique_id mod_unixd mod_userdir mod_version mod_vhost_alias mod_dav mod_dav_fs mod_dav_lock mod_lua prefork mod_proxy mod_lbmethod_bybusyness mod_lbmethod_byrequests mod_lbmethod_bytraffic mod_lbmethod_heartbeat mod_proxy_ajp mod_proxy_balancer mod_proxy_connect mod_proxy_express mod_proxy_fcgi mod_proxy_fdpass mod_proxy_ftp mod_proxy_http mod_proxy_scgi mod_proxy_wstunnel mod_ssl mod_systemd mod_cgi mod_php5
Problem
I’m trying to redirect some pages from my website to the home of another website, but I can’t seem to make it work.
Currently i have this:
redirect 301 /portalwebhttp://www2.tha.com.br
It works if the url is exactly www.oldwebsite.com.br/portalweb
.But if add anything after the portalweb
it redirects to this: http://www.mywebsite.com.br/anything
I have tried the following solutions:
redirect 301 /portalweb$ http://www.mywebsite.com.br
Redirect "/portalweb$" "http://www.mywebsite.com.br/"
RedirectMatch ^portalweb/$ http://www.mywebsite.com.br
RewriteEngine On
RewriteRule "^portalweb$" "http://www.mywebsite.com.br/" [R,L]
RewriteRule "^portalweb/$" "http://www.mywebsite.com.br/" [R,L]
When i add any of the solutions above, it just doesn’t work at all. It seems that the $
character make the redirect not work.
Thanks in advance.
2
Answers
Using the answer stackoverflow.com/q/6877486/4139335 that was sugested by @MichaelWarner. I notice that i was missing a
301
in myRedirectMatch
This worked:
RedirectMatch 301 ^/portalweb/$ https://www.mywebsite.com.br
I don't know why the301
did the trick, if someone explain it to me, i would be glad.RedirectMatch
is equivalent to Redirect, but makes use of regular expressions, as exampled here.Redirect
default status code is 302 as explained here.If you change the status code to 301 this should fix it.