1

I am using Drupal 7. Many of my url paths (up to 6,000) have moved to new url paths with no 301 redirect so they are returning lots of 404s on google. i have paths like /articles/bla/bla-bla/12345 which moved to /articles/bla-new/something/12345

Since the old path which now returns a 404 has the node id in the url at the end, i want to redirect a path like this "/articles/bla/bla-bla/12345" to node/12345 once the system detects a 404

Any suggestions for using .htaccess redirect rules or other module to achieve this?

I've tried this: RewriteRule ^articles/*/+ node/+ [R=301,L] but it doesnt look right.

I need some help. thank you in anticipation

1

Try

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/.*/.*/(.*)$ /node/$1 [R=301,L]

of not worked use your absolute URL

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/.*/.*/(.*)$ http://www.yourdomin.com/node/$1 [R=301,L]
  • Does the code above have a rule to detect if the url returned a 404? Thank you – IT Pro Manager Mar 30 '17 at 21:39
  • @ITProManager No, I don't write rule, do you want I add it or you can ? I just redirect what you need. – Yusef Mar 30 '17 at 21:40
  • yes i would like the rewrite only when the page returns a 404, not for every url, can you include some code or expression for that? thank you – IT Pro Manager Mar 30 '17 at 23:54
  • @ITProManager I update the answer ,try that. – Yusef Mar 31 '17 at 6:29
  • 1
    @ITProManager the first rule needs to have a slash in front of node/$1 like /node/$1 otherwise it will expand it to the file system as oppose to web path. Secondly, I don't think you can detect a 404 at .htaccess level, since this all happens before the application receives your request and sends a 404 response. The only option sounds like for you to write a hook_init and detect if there's going to be a 404 response, parse the URL and do a redirect yourself. See this answer for the basics – Beebee Mar 31 '17 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.