I get tons of url with undefined added at the end of url, consisting about 20% of my pageview. I tried to check the troubling script source and can't find it. Tried some solutions but none of them are working. Lastly now i'm trying to send url with undefined string to redirect 204 using htaccessis this correct?RewriteRule ^undefined$ - [R=204,NC,L]do i need to add last L flag?where do i put it?above wordpress?<IfModule mod_rewrite.c>RewriteEngine OnRewriteRule ^undefined$ - [R=204,NC,L]</IfModule># BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPressinside wordpress?# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteRule ^undefined$ - [R=204,NC,L]RewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPressor after wordpress?# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteRule ^undefined$ - [R=204,NC,L]</IfModule>i've looking for this everywhere, and i want to make sure if this is correct by asking on this stack who dealt with this often. thanks a lot!
redirect 204 with htaccess if url contain certain string
htaccess;apache;mod rewrite
In order to match undefined at the end of the URL-path you need the regex pattern undefined$. The pattern ^undefined$ (which you've used in your question) matches the exact URL undefined, which is never going to match, unless the request is for http://example.com/undefined.This directive should go at the top of your .htaccess file (after the RewriteEngine On directive). You only need one RewriteEngine On directive at the top of your script.So, if you are sure that these requests are coming from your site then you could serve a 204 No Content as you are doing (yes, the L flag is required).RewriteRule undefined$ - [R=204,NC,L]In compliant browsers, as far as the user is concerned, literally nothing happens if the user follows such a link (if this really is a link they are clicking on). However, this can obviously be confusing for the user. Also, if this is an external website that is linking to you, then again, nothing happens when the user clicks the link - they don't reach your website.However, it would be preferable to redirect to the correct URL (if it's simply a case of removing the undefined portion from the end of the URL-path). This would catch all situations and inform search engines of the correct URL (reports in the linked articles suggest that Googlebot is also crawling these URLs).RewriteRule (.*)/undefined$ /$1 [R=301,L]