Forum Moderators: phranque

Message Too Old, No Replies

htaccess %3F redirect issue

         

udayasl

6:44 am on Mar 11, 2023 (gmt 0)



I'm having a htaccess redirection issue which I am unable to find a solution by searching on the Internet and also I did several htaccess rewrite codes, but nothing helped me.

Please give me a correct solution to redirect following URL using htaccess:

https://www.example.com/chat/%3F

To

https://www.example.com/chat/

[edited by: phranque at 8:10 am (utc) on Mar 11, 2023]
[edit reason] exemplified urls [/edit]

phranque

8:09 am on Mar 11, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], udayasl!

I did several htaccess rewrite codes, but nothing helped me.

what have you tried and what results did you get?

udayasl

9:16 am on Mar 11, 2023 (gmt 0)



Sorry, this is the code, previous one is wrong,

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^chat\/%3F "https\:\/\/www\.example\.com\/chat\/" [R=301,L]

This didn't work

[edited by: phranque at 12:24 pm (utc) on Mar 11, 2023]
[edit reason] Please use example.com [webmasterworld.com] [/edit]

not2easy

1:24 pm on Mar 11, 2023 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Does your site not have a canonical redirect to specify www-non www? That can cause duplicate content problems if people can see both versions of your site, because robots can see that as two different sites.

Are you only concerned about removing the /? query from the URL?

lucy24

6:38 pm on Mar 11, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Now, wait, we had an identical problem just the other day:

[webmasterworld.com...]

Read that thread. Do you have the same host? I don't think we have yet figured out how the ? got changed into %3F.

Canonicalization redirects are best done as a negative: if the hostname is anything OTHER THAN your preferred form (with/without www, http rather than https), for example
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$

Edit: You don't need to escape anything in the target, like : or / and so on. It does no harm, but it's just needless clutter.

blend27

11:44 pm on Mar 11, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why do even entertain %3F in %{HTTP_HOST} or URI?

lucy24

2:05 am on Mar 12, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nobody is entertaining it. By some mechanism as-yet unknown, some aspect of the server is converting ?--which is trivial to deal with--into %3F--which isn’t.

Sgt_Kickaxe

2:22 pm on Mar 14, 2023 (gmt 0)



For some time now Search Console lists ALL redirects as an error and John Mu said that not all errors merit a "fix", some are normal, expected and intentional. Search is only a guide, a helper if you will.

https://www.example.com/chat/%3F should serve the same content as https://www.example.com/chat/ so if you have a proper canonical on https://www.example.com/chat/ pointing to itself then there is no issue.

Sometimes Google finds broken urls on other sites, it's actually a common negative SEO tactic to throw crappy backlinks at a competitor to urls that will confuse search, cause duplicate etc.... the canonical is the solution to potential ranking issues. Use redirects sparingly moving forward, unless a page is indexed and people are finding it.

blend27

3:13 pm on Mar 14, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sgt_, that hit a nerve a bit. I was just about to ask a shared hosting account company for a refund for the last 3 month.

Apparently someone wrote a script to add an A record when domain is added to control panel to point out that *.example.com is Observing all the Sun.

That was picked up by a savvy "Negative SEO team member" of lets say of a competitor. Then that purples up into a someone just dumping a few pages on obscure corners of INTERNETS with several hundred variations of NONE-WWW as valid link subdomain for *.example.com.

..and guess what these 2 lines did?
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$

Be very, very advised of what RewriteCond after above 2 lines do..


It allowed ethical spiders and plain dumb bots(take hrefs bot for example) to try to follow the redirect. And those attempts will not stop for next several years as experience tells.

THIS IS A PROBLEM.

Instead of looking at clean Website Access logs we were looking at one in 100 of actual proper requests. Big Gorilla Clean up team needed to be sanctioned to make any sense of it.

We don't want to look at 500 redirects in every iteration for numb script kiddie looking at "wp-|.php|admin|.env"....etc... each day , or do we?

blend27

3:24 pm on Mar 14, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In my humble view: This is the Way(a true Mandalorian would say that..)

If you can, avoid redirects at all costs. Someone types ww.example.com << this one is a given OK.

Someone is trying to access lucy-blend-sg.example.com should not redirect to anywhere, be it on port 80 0r 433. IIF possible, drop the request before it allows to propagate down stream.