php - Remove Some Characters From URL Using 301 Redirect htaccess? -


I type some of the letters ? M = 1 & amp; From the end of my code to ? M = 0 For this purpose, I used javascript from a blog post and edited it with the desired work below it and its fine work.

  & lt; Script type = 'text / javascript' & gt; Var curl = window.location.href; If (curl.indexOf ('m = 1')! = -1) {curl = curl.replace ('m = 1', ''); Window. place. Href = curl;} Var curl = window.location.href; If (curl.indexOf ('m = 0')! = -1) {curl = curl.replace ('m = 0', ''); Window.location.href = curl;} & lt; / Script & gt;  

This is removing my desired additional characters and then redirecting to the new URL, but according to Google SE is not friendly and me through the 301 redirection .htaccess which will tell every search engine that this URL is now changing to it.

My URL is being shown as http://www.blog.com/2014/08/post-title.html?m=1 & amp; http://www.blog.com/2014/08/post-title.html?m=0 now ... then do this by using .htaccess Can and 301 redirects ?

You can do this by using mod_rewrite. You can check the query string in a condition with % {QUERY_STRING} and you can use the [R = 301] flag to create a permanent redirect The QSD flag will abandon the query string. In Apache 2.4 and above, you can use the following:

  RewriteCond% {QUERY_STRING} meter = [01] Apache QSD flag is not present in earlier versions of RewriteRule ^ http: //% {HTTP_HOST}% {REQUEST_URI} [QSD, R, L]  

you have a move Where you will have to use the writing type above the query string by adding an empty query string for the goal of re-writing.

  RewriteCond% {} QUERY_STRING M = [01] rewrite rule ^ http: //% {HTTP_HOST}% {REQUEST_URI}? [R, L]  

Change R to r = 301 while working as expected, please note that you Another rule for your blog should be first . At the end of sending your blog backend request, a catch-all rule is most likely, and you have to redirect before this happens.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -