Hi Can someone explain what this rule will exactly do. I want to know what is the role of ? towards the end.
RewriteRule ^(products/someproduct.html)$ https://www.myserver.com/? [R=301,L]
looking forward for a quick explanation on the last character ?
This prevent appending the query string to the new URL.
for example, a request for https://www.myserver.com/products/someproduct.html?qu=1&bu=2:
with ? : get redirected to https://www.myserver.com/
without ? : get redirected to https://www.myserver.com/?qu=1&bu=2
Related
There's a site that has had a bunch of bad links indexed and I've been asked to deal with it. There's one type of link that is giving me a headache:
http://www.example.com/category-display.html&Category_Code=some_cat_code
I tried redirecting to the home page:
Redirect 301 /category-display.html& /
That doesn't work because it adds everything past the & to the url.
In the best of worlds, I'd like to redirect to:
/app/mm.mvc?Category_Code=some_cate_code
So I tried using querystring and RewriteRule/RewriteCond but there's no query string without the ? that I can figure out, so I'm kind of stuck here.
Any ideas?
You can use this rule as your top rule in site root .htaccess:
RewriteEngine On
RewriteRule ^category-display\.html&(.*)$ /app/mm.mvc?$1 [L,NC,NE,R=301]
Let me show you a simple example to demonstrate it.
You got this URL :
www.bowling.com/account.php?id=30&pref=t,s,m&cr=32
Then, with .htaccess you do this following :
RewriteEngine On
RewriteRule ^Your-Account/Identity/$1/?$ account.php?id=$1&pref=$2&cr=$3 [flag(s) u want]
Now, instead of having the first URL, y'all can guess, I got this back :
www.bowling.com/account.php?Identity/30/
The two next $_GET var are now invisible in your URL. Is this a good security secure or just a waste of time? What's your opinion?
i have been trying to find the solution through previous question on SO, but im getting errors when using them.
how to make this url : /viewpost.php?postid=81 as /viewpost/81 in the url so that when /viewpost/81 is entered, it shows the content of /viewpost.php?postid=81?
You must capture the number and append this number as part of the query string
RewriteRule ^viewpost/(\d+)$ /viewpost.php?postid=$1 [L]
First of all, sorry for my english... I hope you're going to understand my problem :)
My company has made an emailing campaign which included a link to our website. This URL has a Google tracking code to follow the campaign.
Unfortunately, the URL is wrong :
http://www.mysite.fr/category/mypage.html/?utm_source=source&utm_medium=medium&utm_campaign=campaign
but there's a slash between "mypage.html" and the tracking code which points to an inexistant page.
I tried these rules to redirect the url without sending a new email to everyone but they don't work :
RewriteRule ^/category/mypage\.html/\?utm_source\=source\&utm_medium\=medium\&utm_capaign\=campaign$ http://www.mysite.fr/category/mypage.html?utm_source=source&utm_medium=medium&utm_campaign=campaign [R=301,L]
Or :
RedirectPermanent /category/mypage.html/ http://www.mysite.fr/category/mypage.html?utm_source=source&utm_medium=medium&utm_campaign=campaign
I don't know how to write the rule. Can someone help me please ?
A few things are wrong with your RewriteRule. If you're putting this in an .htaccess file, you need to remove the leading slash (the prefix) in your regular expression because apache removes it from the URI before putting it through rules in .htaccess files. Second, you can't match against the query string (the stuff starting from the ?) in the regular expression in a RewriteRule.
Not sure why your RedirectPermanent isn't working. That looks fine other than the fact that the query strings automatically get appended if you leave them out. I think that's what you want, so remove the query string in the target:
RedirectMatch 301 ^/category/mypage.html/$ http://www.mysite.fr/category/mypage.html
I have an htaccess redirect that needs to forward the query string to the new URL, but it's getting dropped after the redirect. Can someone tell me what's wrong?
RewriteRule ^services/agents.*$ https://services.example.com/agents/ [R=301,L,QSA]
The same rule is working fine on my server. The problem should be something else.
I added the same rule on my server and I get the following redirect
http://mysite.com/services/agents/foo?foo=bar => https://services.mysite.com/agents/?foo=bar
Please note that you don't need to add the QSA flag since the target doesn't include any query string.
This article might contain some useful information to help you dealing with Htaccess and Query String.
In general there is no need to explicitly append the query or use the QSA flag if you don’t specify a query for the substitution. But as you said your rule doesn’t work, try this:
RewriteRule ^services/agents.*$ https://services.example.com/agents/?%{QUERY_STRING} [R=301,L]