0

I am trying to redirect everything with a link of /Drug-Charges/ to simply /

I've been trying both 301 redirects as well as Rewrite Rules and have had no luck.

RewriteCond %{REQUEST_URI} ^/Drug-Charges/(.*) [NC]
RewriteRule ^/Drug-Charges http://www.domain.com/$1 [R=301,L]

What am I doing wrong here? I've enabled the rewrite engine and everything.

Here's the whole top portion:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.aspx$ $1.html [R=permanent]
RewriteRule ^Landing-Pages/(.*) County-Resources/$1 [R=permanent]
#RewriteRule ^Practice-Areas/Sex-Crimes/(.*) /$1 [R=permanent]

rewriteRule ^index\.(php|html|htm|asp) http://www.domain.com/ [R=permanent,L] 


RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

RewriteRule ^Drug-Charges/(.*) /%1 [R,L]
Steven Matthews
  • 9,705
  • 45
  • 126
  • 232

2 Answers2

0

You have two issues in your rule

  • (.*) in a RewriteCond is accessed as %1, not $1
  • In a .htaccess context, the leading slash is removed from the request URL path

To cut out /Drug-Charges from the request URL, you need only

RewriteRule ^Drug-Charges/(.*)$ /$1 [R,L]

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

It would be better to do this kind of redirection without using the REQUEST_URI reference.

RewriteRule ^Drug-Charges/?(.*)? $1[L,NC,R=301]

This rule basically checks if the request starts with Drug-Charges, and anything optional following it, and redirects accordingly.

Note that you should remove the REQUEST_URI reference altogether.

Mike Rockétt
  • 8,947
  • 4
  • 45
  • 81