Search code examples
.htaccessmod-rewritedrupal-7

Trouble getting mod rewrite to substitute pattern in URI in Drupal


I changed the path in Drupal for a number of nodes and I need any external links that reference the old path to redirect to the new path. I don't know if path is the right word since everything is directed at index.php For example, the old ones were reached at http://domain.com/thepress/node/1111. In Drupal they've been changed to http://domain.com/thenews/node/1111. I need to redirect to the new uri any external urls that request those "pages" My .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico 
RewriteRule ^thepress/([^.]+)  thenews/$1 
RewriteRule ^ index.php  [L]

Any help is appreciated. I want to just strip the substring /thepress/ and replace it with /thenews/ and pass that to index.php for drupal to pull up the correct pages.


Solution

  • You need to redirect old URL to new one using R flag. Try these rules:

    RewriteRule ^thepress/([^.]+)$ thenews/$1 [L,NC,R=302]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule ^ index.php  [L]