I have discovered that some visitors to my site connect with a weird URL:
Example: http://www.example.com/article/?epik=3xFD_XXs
The trouble is, when "?epik=3xFD_XXs" is added to a URL, it causes me to lose ads on my website!
So, I would really like to find a solution.
I'm presuming that the solution would be to redirect them to the original URL, http://www.example.com/article/, whenever ?epik=Random_char is found.
Thank you.
This RewriteCond is to check whether the request query string contains epik=. If it contains the query string epik=, the RewriteRule redirect is then applied. The ? character is used to remove query string if any.
RewriteCond %{QUERY_STRING} epik=
RewriteRule ^ %{REQUEST_URI}? [R,L]
Related
This is so elementary that you have to ask why it is so complex to implement.
Simply need to redirect one url to another on the same domain, the url contains query string aparams though:
I tried:
RewriteRule ^article.php?section=exclusive&id=543 articles/view/4639 [R=301,L]
I get page cannot be found - the redirect is not happening. I have other re-directs in the same htaccess which work. The query string params are causing problems, and escaping them also does not help.
Note the id's of the two urls are not the same and therefore I don't want a clever re-write rule which converts from one url to another with the query strings mapped to new params. I just want a fast and dirty mapping from A to B.
UPDATE
I tried this it redirects but it is adding my old query string to the end of the new url. How can I prevent that?
RewriteCond %{REQUEST_URI} ^/article\.php$
RewriteCond %{QUERY_STRING} ^section=exclusive
RewriteRule ^$ http://www.onlinegooner.com/articles/view/3000 [R=301,L]
Input url is: mydomain.com/article.php?section=exclusive
You may use this rule:
RewriteCond %{QUERY_STRING} ^section=exclusive [NC]
RewriteRule ^article\.php$ /articles/view/3000? [R=301,L,NC]
? in the target will strip off previous query string.
I have a situation where I want to actually see the url variable even though the rest of my htaccess site uses readable URLS.
The issue is that it is simply showing up as a page not found...
This works...
RewriteRule ^files/(.+)/from_all_files/$ pages/file.php?slug=$1&from=all-files
This does not work
RewriteRule ^files/(.+)?from=all-files$ pages/file.php?slug=$1&from=all-files
Im looking for the second one to work.
You cannot check the query string in a RewriteRule, which can only see the REQUEST_URI. You need to use the following instead:
RewriteCond %{QUERY_STRING} ^from=all-files$ [NC]
RewriteRule ^files/(.+)$ pages/file.php?slug=$1 [QSA,L]
When you request http://example.com/files/some-file?from=all-files, the request will be internally rewritten to pages/file.php?slug=some-file&from=all-files. The Query String Append flag (QSA) will append the current query string to the one you're rewriting to.
url = www.example.com/de/abc
I just want to change fix url word 'abc' into fix word 'xyz' for browser compatibility only changed url show in browser. But change url point to actual directory path means
www.example.com/de/xyz will follow internally www.example.com/de/abc.
I used some regex to do this, but not able to get actual solution
How can I do this.
Thanks in advance
Code from comment :
RewriteCond %{REQUEST_URI} ^/de/advertiseWithUs$ [NC]
RewriteRule ^(.*) /de/unsere-tipps [R=302,L]
If I have correctly understood what you want, here a solution you can try :
RewriteRule ^de/advertiseWithUs$ http://yourdomain.com/de/unsere-tipps [R=302,NC,L]
RewriteRule ^de/unsere-tipps$ de/advertiseWithUs [NC,L]
The first rule change URL (with a 302 redirection), the second one make the internal redirection to point to the right page.
Trying to make the url:
www.google.com/forum.php?fid=5
Redirect to:
www.google.com/new.php?fid=5
But also need it to keep everything else intact because for example the link can be:
www.google.com/forum.php?fid=5&sortby=asc
And need sortby portion to be there upon redirect.
What the redirect needs to do is look for forumdisplay.php and fid=6 and when both are found in the same url it redirects to blog.php and removes fid=6 but keeps any other parameters there.
I searched and found how to do it with one string but not two.
Also, what's the difference between redirect and rewrite?
This is related to MyBB forum software. I made a separate php file that uses forumdisplay but with a new name.
Using mod_rewrite you could use a condition to verify the id and grab what comes after if anything:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/forumdisplay.php
RewriteCond %{QUERY_STRING} ^fid=6(&.*|.*)
RewriteRule ^.*$ /blog.php?%1 [R=301,L]
It's been necessary to move the position of my blog and I'm trying to make sure I catch all of the links in via the old link and redirect them to the new one.
The blog has been moved from http://example.com/ to http://example.com/blog/
The URLs used to generate with the date before the post name (by default) which I've decided not to do, to keep the URLs memorable.
The issue is that there's a ? character in the original URL (the default URL produced by the CMS I'm using and it's causing problems with the redirect:
RewriteRule ^post.php?s=2012-01-01-blog-post$ /blog/blog-post? [R=301,L]
So I need to escape the ? somehow but I can't work out how!
I could use a more general redirect that avoids the ? but that would redirect to the listings page, not the article itself:
RewriteRule ^post.php$ http://tempertemper.net/blog/? [R=301,L]
How do I make it read the ? as part of the URL!?
Thanks for taking a look!
Martin :)
I think you need to use a RewriteCond to check for the presence of a QUERY_STRING value and then, assuming the query string matches your blog pattern, capture the blog name and then use the captured value in the RewriteRule. Something like this:
RewriteCond ${QUERY_STRING} ^s=[0-9]{4}-[0-9]{2}-[0-9]{2}-(.*)$
RewriteRule ^post.php$ /blog/%1 [R=permanent,L]
The %1 refers to the first capture pattern in the matching RewriteCond (and the RewriteRule will not trigger unless the RewriteCond is a match).
The reason this is necessary is that a RewriteRule cannot see the query string as part of the request path, so you have to check for (and capture) a query string using a RewriteCond before the RewriteRule.