301 Redirect URL Appending Query String

by 3 replies
4
Hello Friends, From yesterday, I'm trying this 301 url redirect but its not working as expected. Please help me with this. here is the .htaccess file code.

Code:
Options +FollowSymLinks +SymLinksIfOwnerMatch -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteBase /
rewriterule ^(.*)/(.*)\.html$ product.php?id=$1&name=$2 [L]
rewriterule ^deals/(.*)$ details.php?id=$1 [L]
rewritecond %{SERVER_PORT} 80
rewritecond %{REQUEST_URI} publisher.php
rewriterule ^(.*)$ publisher.php [L]

Redirect 301 /deals/74/product-name.html http://mydomain.com/74/product-name.html
Whenever I enter www.mydomain.com/deals/74/product-name.html", It redirects me to "www.mydomain.com/deals/74/product-name.html?id=74&name=product-name"


I'm not sure why its appending "?id=74&name=product-name" after url?


I want to display only "www.mydomain.com/deals/74/product-name.html"


I cant figure out how to fix this problem. I'll appreciate if you can guide me on this.
#programming #301 #appending #query #redirect #string #url
  • There's lots of redirects.
    On the last line you have http://mydomain.com/ maybe you should have it http://www.mydomain.com/....
    Actually, that is the line [Redirect 301 ....] which appends the query string.

    You already have a redirect to www. prefixed requests

    maybe you can try enabling the rewrite log

    RewriteLog “/var/log/httpd/rewrite.log”
    RewriteLogLevel 9
  • This is an easy problem to fix if you are using Wordpress. You just need to install a Wordpress plugin to do a 301 redirect to wherever you want to take your visitors.

    You can install: Redirection – Manage 301 redirections without modifying Apache | Urban Giraffe

    Enter "www.mydomain.com/deals/74/product-name.html?id=74&name=product-name" in the first box and then enter www.mydomain.com/deals/74/product-name.html" in the destination url box and you are done.

    I hope this solves your problem, it has worked for me.
  • you can use a htaccess generator to create simple redirect . Use this htaccess redirect

Next Topics on Trending Feed

  • 4

    Hello Friends, From yesterday, I'm trying this 301 url redirect but its not working as expected. Please help me with this. here is the .htaccess file code. Code: Options +FollowSymLinks +SymLinksIfOwnerMatch -MultiViews RewriteEngine On RewriteCond %{HTTP_HOST} ^mydomain.com [NC] RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301] RewriteBase / rewriterule ^(.*)/(.*)\.html$ product.php?id=$1&name=$2 [L] rewriterule ^deals/(.*)$ details.php?id=$1 [L] rewritecond %{SERVER_PORT} 80 rewritecond %{REQUEST_URI} publisher.php rewriterule ^(.*)$ publisher.php [L] Redirect 301 /deals/74/product-name.html http://mydomain.com/74/product-name.html Whenever I enter www.mydomain.com/deals/74/product-name.html", It redirects me to "www.mydomain.com/deals/74/product-name.html?id=74&name=product-name"