Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#720 closed Question/How do I...? (fixed)

How to modify .htaccess?

Reported by: Ilyse Kazar Owned by: Jamie McClelland
Priority: Medium Component: Tech
Keywords: htaccess drupal Cc:
Sensitive: no

Description

We're switching our site over to May First / Drupal this weekend. I'm trying to set up htaccess redirect so that the old URLs (index.php?name=home) will redirect to the new URLs (/home). How do I go about modifying the .htaccess file in our directory? I get a permission denied error when I try to upload a new .htaccess file.

Change History (10)

comment:1 Changed 11 years ago by Jamie McClelland

Keywords: drupal added

Drupal can do that for you by enabling "clean URLs" (you should see that option by logging into Drupal and clicking Administer -> Settings.

The existing .htaccess file should already be configured to do that.

The reason you are not able to edit your existing .htaccess file is because that file is a link to our central Drupal installation that is shared amongst all members. By sharing the Drupal code this way - we can apply security updates in one place and they are applied to all members at once.

If you want to have your own .htaccess, you can delete the linked file (although you don't have permission to edit the file, you do have the ability to delete it). Then, you can upload your own version. Although you can do this, we don't recommend it because when we upgrade Drupal next - if there is a update to this file you will not benefit from it.

comment:2 Changed 11 years ago by Ilyse Kazar

I deleted the link to the .htaccess file to try to get this to work, but I haven't been successful. Can you restore the link to the shared .htaccess file?

Also, I'm not sure the clean urls you're referring to can address our issue. Our old pagetool site had links like this: http://www.champnetwork.org/index.php?name=solid

Obviously, those links are no longer valid since we moved to Drupal. When I created our new site in Drupal, I kept the same name for each page. However, they have different URLs in Drupal: http://www.champnetwork.org/index.php?q=solid or http://www.champnetwork.org/solid

I was hoping to use the .htaccess file to rewrite url requests for "/index.php/name=[page_name]" to simply "/[page_name]"

comment:3 Changed 11 years ago by Jamie McClelland

I just restored your .htaccess link.

For future reference, you can re-create the link by going in via secure shell. Once you are in, type:

cd champnetwork.org/web
mv .htaccess .htaccess.champ
ln -s /usr/local/share/drupal-5/.httaccess

As for the rewrites, you could do that via the Members Control panel. Select Web Config from the services menu, the click to edit your web configuration.

You could add something like this:

RewriteEngine On
# match any URL that has name= in the query string
RewriteCond %{QUERY_STRING} name=(.*)
RewriteRule . http://champnetwork.org/%1? [L]

This assumes that none of your current pages uses name= in the query string!

Jamie

comment:4 Changed 11 years ago by Ilyse Kazar

Priority: MediumLow
Resolution: fixed
Status: newclosed

Thanks!

comment:5 Changed 10 years ago by Ana Willem

Priority: LowMedium
Resolution: fixed
Status: closedreopened
  1. i am understanding that there is a risk when we do updates that we won't get the benefit of having the update for the .htaccess file. in this case the pros for changing it outweigh the cons...unfortunately for me. so here is my plan. wanted to go over it with you so that i can do this in a smart way:

1) download the contents of the .htaccess file that i share with the main drupal installation. 2) in the location where it is relevant...after: <code># Various rewrite rules. <IfModule mod_rewrite.c>

RewriteEngine on

# Modify the RewriteBase if you are using Drupal in a subdirectory and # the rewrite rules are not working properly. #RewriteBase /drupal

RewriteBase /</code>

comment out that these are the redirects and add those. Also comment out when it is the end of those redirects.

3) delete the shared .htaccess file (i have a backup on my computer but don't think i have permission to add to that folder - so might need help if things go wrong...) and add the new one.

4) when updates happen, copy and paste the parts i added before into the updated .htaccess file and upload it into that folder.

Do I have permissions to do all this? Is this the best way to go about this. The issue is that the old site had whack organization, and so when we organized the new one, many of those urls changed. Because people use this as a research site, we need to restore their old bookmarks.

An alternative way to go about this would be to create the old nodes (urls) and then use a php redirect on the node itself. Is this a better idea in the long run?

Let me know!

I appreciate you all. Ana

comment:6 Changed 10 years ago by Jamie McClelland

Hi Ana,

Is there are reason not to put the Rewrite Rules in your apache configuration in the [https;members.mayfirst.org/cp Members Control panel]? That was my suggestion to champ, which seems to have worked for them. That way you don't have to maintain a custom .htaccess file.

If you do need to modify your .htaccess file, you plan sounds fine and you should have permissions. Simply delete the symlinked .htaccess file, copy in the original from Drupal, and then make your modifications. Then repeat on every upgrade.

hth,

Jamie

comment:7 Changed 10 years ago by Ana Willem

Resolution: fixed
Status: reopenedclosed

woops. didn't see that. i'll definietly give that a whirly-gig. you are always so helpful. thanks, jamie!

btw- these resources are SO helpful. i'm very thankful. is it important where these go? inside the directory tags?

comment:8 Changed 10 years ago by Ana Willem

one last thing...is there a way to do wildcards, so that if the old url is something like:

http://mysite.org/prison

can you do a redirect for:

http://mysite/prision/*

thanks! ana

comment:9 Changed 10 years ago by Ana Willem

my question above might mean that i'm not getting it... it seems to be a wildcard? i guess i'm not clear if there are parts of it i need to modify and if so how they would be modified...

i pasted the code inside the directory tag of my web configuration file, and then tried to look up a page from the old site, and it gave me a 404. sorry that this is all in so many little emails...

comment:10 Changed 10 years ago by Jamie McClelland

I just opened ticket #1751 to answer these questions - I think we're straying from the original intent of this ticket.

Please login to add comments to this ticket.

Note: See TracTickets for help on using tickets.