0

Thanks in advance for helping me. I am new here and also new to redirect rules. I have an issue after .htaccess 301 redirect I did on my website url's.

  1. First, the URLs slugs were with "_" (underscore).
  2. 2nd, I change URL's structure from "_" to "-" (hyphen).
  3. I now did .htaccess 301 redirects from old URL to the new URLs.

ISSUE: when I redirect the URL, and try to click my URL from google search it worked, but with extra slugs (?promo/sports_and_outdoors_coupons=23&hta&ext=) in the URLS.

Here is my .htaccess code:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)(\-(\d+))?([.]\w+|\/)?$ index.php?$1=$3&hta&ext=$4 [QSA,L]
Redirect 301 /promo/auto_parts-26 /promo/auto-parts-26
Redirect 301 /promo/bath__body-27 /promo/bath--body-27
Redirect 301 /promo/computers_and_electronics-8 /promo/computers-and-electronics-8
Redirect 301 /promo/health__wellness-13 /promo/health--wellness-13
Redirect 301 /promo/home_and_garden-14 /promo/home-and-garden-14
Redirect 301 /promo/musical_instruments-16 /promo/musical-instruments-16
Redirect 301 /promo/office_supplies-17 /promo/office-supplies-17
Redirect 301 /promo/party_supplies-18 /promo/party-supplies-18

After clicking url from google search, this is the permanlink on my website:

https://website.com/promo/auto-parts-26?promo/auto_parts_26=26&hta&ext=

I need quick fix, would you kindly help, what I am doing wrong. thank you.

Main issue occurring from this part

 RewriteRule ^(.*?)(\-(\d+))?([.]\w+|\/)?$ index.php?$1=$3&hta&ext=$4 [QSA,L] 

I removed it, url redirect correctly, but page was not loading. url not found error.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
hassan
  • 1
  • 1
  • Main issue occurring from this part `RewriteRule ^(.*?)(\-(\d+))?([.]\w+|\/)?$ index.php?$1=$3&hta&ext=$4 [QSA,L]` I removed it, url redirect correlty, but page was not loading. url not found error. – hassan Nov 14 '18 at 19:59
  • What you call the "extra slugs" is there because of flag QSA. You are telling RewriteRule to do that, see https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_qsa – Nic3500 Nov 15 '18 at 12:39
  • Note for your RewrireRule with index.php: what url do you expect this rule will receive? I think you are trying to setup a rule to look at the contents **after** the `?` sign. Everything after the `?` is considered the QUERY_STRING, not part of the URL per say. So your rule will never work. See https://stackoverflow.com/questions/2252238/how-can-i-match-query-string-variables-with-mod-rewrite – Nic3500 Nov 15 '18 at 12:45
  • there is no method for my redirects to work? I am not familiar with the htaccess rewrite rules etc. that is why I am here.. I need help. to make it work. – hassan Nov 15 '18 at 20:39
  • Edit the question with: the requirement. What are you trying to accomplish exactly, with details. Then what you have tried, the expected result and the current result. It is also required for you to post your tests and show how they failed. Right now we have some rules and a line you say has an issue. Lastly I suggest you read on mod_rewrite, and understand the difference between the QUERY_STRING and the REQUEST_URI. – Nic3500 Nov 16 '18 at 01:48

0 Answers0