3

In Drupal 6 I used the following snippet of code in my .htaccess file to extract information from a non-existent URL and pass it to an existing URL in a GET form. However, it isn't rewriting the URL with my Drupal 7 installation and when I visit a URL the should be rewritten, I just get a Page Not Found error! I have cleared all caches and even tried different browsers:

# Custom Rewrite  ScriptOptions +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^home/code/([^/]+) home/software?code=$1 [L,NC,QSA]

I have placed the code just after the default handler is set.

Could anyone tell me why this code isn't working? Should I be doing this a different way in Drupal 7?

UPDATE: Please see the question I asked on Stackoverflow to get this code working with Drupal 6 - https://stackoverflow.com/questions/10765799/rewrite-a-url-to-include-get-data-with-drupal

  • Just some notes, but you may want to use a RewriteCond to match your URL prior to the RewriteRule. Also, keep in mind the [L] flag means "Last" or "Stop processing other rules" at that point. – David Thomas Jan 6 '13 at 20:57
  • @DavidThomas Thank you for your comments. To be completely honest with you, I'm not really that familar with .htaccess files. I'm just using what I got from Stackoverflow with my limited knowledge of regular expressions - so I've now removed the [L] flag – Andy Jan 11 '13 at 21:11
5

Handling of "Clean URLs" has changed from Drupal 6 to Drupal 7 in a way that affects Apache RewriteRule.

I'm not sure if that is what has bitten you since I don't recognise home/software?code=$1 as a typical Drupal URL. But I've found that in Drupal 7 I need to rewrite to a "unclean" URL.

For instance, the following will work in Drupal 6, but not in Drupal 7:

RewriteRule ^home/code/([^/]+) home/software/node?code=$1

In Drupal 7 you must not rewrite to a clean URL destination, even if you have clean URLs enabled. The following will work in Drupal 7:

RewriteRule ^home/code/([^/]+) ?q=home/software/node/&code=$1
  • Thank you for your answer - that is very interesting. What I am trying to achieve is a GET request. The part of the URL I have extracted is the information that should be in 'code'. I have updated my answer to include my original question on Stackoverflow with Drupal 6 which should make everything a bit more clear – Andy Jan 6 '13 at 18:44
  • I have made an edit to your answer to make it everything that I needed because based on your comments about clean URLs I managed to get the RewriteRule working in Drupal 7. So thank you once again – Andy Jan 11 '13 at 21:07
  • Ok, no problem. It was worth a try - its a shame that my edit did not get approved but thank you for making my edits yourself :) – Andy Jan 12 '13 at 10:44
0

Very simple

  1. Goto .htaccess file in your drupa7 folder(ie your project folder. it may in in www/drupal_project/ or public_html/drupal_project/).

  2. .htaccess is a hidden file. So go to this this directory structure www/your_project/(or public_html/your_project/) and press ctrl+h.

  3. You will get all hidden files including .htaccess file.

  4. in .htaccess file, go to line number 106

  5. RewriteBase /drupal uncomment this line. Replace drupal by your project folder.

  6. If you are not administrator or if you have an account and you working from that account, specify like this, #RewriteBase /~username/your_project_folder

  7. Save the file

  8. Go to admin/config/search/clean-urls this page.

  9. If everything is ok, you will get Enable clean URLs checkbox.

  10. Enable it and now you have clean URL in your site.

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.