We received some press coverage a few months back, but they mistyped our link as <a href="http://www..oursite.org/" target="_blank" data-component="externalLink">
They're a significant outlet and not interested in responding to our request to correct this typo, so we're trying to redirect it on our side. Is the below rule viable or, if not, is this something that we can resolve at all?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.\.oursite\.org
RewriteRule .* https://www.oursite.org [R=301,L]
I'm very sorry but you can't do this with htaccess. The problem is that the request http://www..oursite.org never hit your server, and therefor you can't do any redirect.
The Domain www..oursite.org has an invalid syntax, so you also can't configure a sub-domain www..oursite.com on your DNS server that points to your Web server and than catch the request and do some redirect.
So the only way is to fix the original link.
Related
Firstly, I can't get the correct code looking at other post here, not working for me hahahaha.
I would like to block this specific url: /2017/06/wonder-womannuestra-princesa-feminista.html?m=1 (Related to an old blogger url)
Don't know why but different ips, without referrer and user agent, are spamming (not a real visit cause after a redirection to the new one on WordPress they visit all the links in the url) my site always entering by this url and I would like to block ONLY this one.
I've tried to redirect this one with Redirection plugin but I have a redirection to all "?m=(*)" and this one is the one working, not the one related to the specific url.
I just used : RewriteCond %{REQUEST_URI} ^/2017/06/wonder-womannuestra-princesa-feminista.html?m=1 but it doesn't work.
Could you help, I think the problem is that I'm not witting the correct code due to the "?" character. Many thanks.
With your shown samples, attempts considering that you need to block url(mentioned in comments/question), if this is the case then try following. This rule will forbid this specific url from being accessed.
Please these rules at top of your .htaccess file. Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/2017/06/wonder-womannuestra-princesa-feminista\.html\?m=1 [NC]
RewriteRule ^ - [F,L]
So, apparently some mobile ads drop a request for mraid.js into their page loads. That feels ridiculous to me, but there's not much I can do about that exactly. It looks like this:
If the page is /something, the request comes in as /something/mraid.js
But that also continues for cases like /something/else/mraid.js
No matter what the URL, it tacks on mraid.js.
I added a couple lines like this to the .htaccess file:
RedirectMatch 301 (.*)\mraid.js$ /mraid.js
or
RedirectMatch 301 ^\mraid.js$ /mraid.js
or
RewriteCond %{DOCUMENT_ROOT}/(.*)/mraid.js -f
RewriteRule ^(.*)$ /mraid.js [R=301,L]
With the hopes of redirecting them to a global (and blank) mraid.js file. This is just to load a file to stop the 404 errors in analytics, from what I'm told when mraid.js is needed it's loaded locally from within the mobile ad/app.
But none of those .htaccess rules seem to catch and redirect as I expect. Any ideas on how to always match mraid.js in the URL and pass it back to root?
After a bit more head-scratching, I figured it out. It was a combination of all three things that solved it for me. First, it had to match the pattern with ^(.*), then [L,R=301]. L for "this is the last rule", and R for "it's a permanent 301 redirect."
RewriteRule ^(.*)/mraid\.js$ /mraid\.js [L,R=301]
I have a website setup at mydomain.com/FR
I'd like to make sure people typing
mydomain.com/fr are being sent to mydomain.com/FR
mydomain.com/fr/aNyTHiNg are being sent to mydomain.com/FR/anything
... whether they type http, https or http(s)://www.
How would I do that using .htaccess ? I'm afraid this is too much of a complex rule for me to sort it out.
You can use this simple rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^fr(/.*)?$ FR$1 [L]
we moved our joomla site and rebuilt. in the process a link got moved that we need to be as it was before.
before:
www.mysite.org/kindergym
now it lives here:
www.mysite.org/education/kindergym
it would seem that it would be easy to go into com_redirect and do this. however, it only works for the following
mysite.org/kindergym without the www
with the www attached writing the old url returns a 404 error page, not a redirect.
i tried to make a separate redirect with the www too and it wouldnt let me. i tried a separate module with no success and have played around with the .htaccess file (although i am not very knowledgeable about htaccess).
could someone explain the reason why this would be an issue? the difference between the two. i tried calling my host and they were less than helpful and actually told me what i wanted to do couldnt be done LOL.
thanks.
I take it the solution you have would work if you redirect the entire mysite.org to www.mysite.org?
If so, create a .htaccess file in the website root. Put the following inside it:
########## Begin - Redirecting non-www request to www
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.org [NC]
RewriteRule (.*) http://www.mysite.org/$1 [L,R=301]
#
########## End - Redirecting non-www request to www
You also need to make sure mod_rewrite is enabled on the apache-server, but I think most providers support that.
I suggest you post your full .htaccess here. However I think all you need is this rule:
RewriteRule ^(?!education/).*)$ education/$1 [L,NC]
The other two answers are good! but better implement 301 redirect in httpd.conf since it's compiled once on server restart. The same code in .htccess is interpreted for each and every HTTP request!
We have the following example "ugly" URL:
https://some.uglyurl.com/directory/test.jsp?hotelid=1111&rateplanid=33333
we need to direct our customers to the above URL using our own domains URL as the address - so it would look something like:
https://www.PrettyURL.com/reservations?hotelid=1111&rateplanid=33333
The idea being that the address our customers "see" is a nice looking "familiar" URL to them. Is this possible in .htaccess? We would tack on various variables AFTER the test.jsp in the ugly URL - so it can't just be a fixed set of variables.
many thanks for any help.
If you were just using plain HTTP, you could set up the pretty URL server as a proxy that passes every request to the ugly URL server and the response back to the client:
RewriteCond %{HTTP_HOST} ^pretty\.example\.com$
RewriteRule ^reservations$ http://ugly.example.com/directory/test.jsp [L,P]
But as you’re using HTTPS, it is not possible without getting an error message, that the certificate’s host name is not correct.
This is the code that worked for me:
RewriteCond %{HTTP_HOST} ^www.prettyurl.com$
RewriteRule ^reservations$ https://uglyURL.com/istay/istay.jsp?%2 [QSA,L]
It works exactly as I needed it.
Many thanks to Gumbo and others for all their help.