Forum Moderators: phranque

Message Too Old, No Replies

Help with htaccess for a site transition

Old site uses shtml, new site uses directory structure

         

urbansam

3:06 am on Mar 8, 2010 (gmt 0)

10+ Year Member



I have used this site several times to answer my questions, and I have appreciated your collected help.

This is my first time posting, and I searched throughout the site, but couldn't find a comprehensive answer. I apologize if this is obvious or if I am not following etiquette. Here we go:

I am building a new site to replace our current site. The old site had links that appeared as:
/community_grants/goals_philosophy.shtml

Our new site would have the same page here:
/community_grants/goals_philosophy/

What is the easiest way to do this? I am thinking an htaccess rule, but I have tried several things that have not worked. Am I just being difficult by not wanting to do this manually for each page?

I hope you can help. Thank you!

g1smd

8:02 am on Mar 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Firstly, make the new URLs have hyphens in place of underscores. The filename on the server will still have underscores and the .html extension.

This is a job for a couple of simple RewriteRules.

One will be a rewrite taking the extensionless URL request and finding the correct file inside the server.

The other will be a redirect such that if the old filename is directly requested from the web, the user is redirected to the new name.

Use RewriteRule for both rules. Both need the [L] flag, and list the redirect before the rewrite.

Also, since a trailing slash is reserved for folders, you would be better off using no trailing slash on your 'extensionless' URLs.

There's very many prior examples that can be adapted to fit your requirements. Let's see your code.

urbansam

4:15 am on May 8, 2010 (gmt 0)

10+ Year Member



So, I am still having trouble and I guess I need to clarify the problem further and include more information.

I am using WordPress, and there is already some rewriting that needs to be done because of the URL structure of WordPress. So, here is my current .htaccess code.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Redirect /publications/issue-briefs/pdfs /pdfs/issue_briefs
Redirect /publications/policy-primers/pdfs /pdfs/policy_primers
Redirect /publications/issue_briefs/pdfs /pdfs/issue_briefs
Redirect /publications/policy_primers/pdfs /pdfs/policy_primers
Redirect /publications/images /images/publications
Redirect /publications/studies_research/pdfs /pdfs/studies_research
Redirect /publications/tools/pdfs /pdfs/tools


What I need is to be able to redirect a link such as:

initiated_programs/assistance.shtml


to the real link for that page, which can be on of the following:

/initiated_programs/assistance/
/initiated-programs/assistance/
/initiated-programs/assistance/index.php
/initiated_programs/assistance/index.php


What can I do? I truly thank you for your help.

g1smd

5:54 am on May 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your Redirect directives are all 302 redirects.

Firstly you should change all of those rules to use RewriteRule and the [R=301,L] flag, so that all of your rules use RewriteRule.

Secondly, you must list the redirects before the rewrites, otherwise you will expose rewritten internal filepaths back out on to the web as URLs.

The rewrite code you have now is very inefficient. The -f and -d checks look at the physical hard disk. Check recent threads for often-posted code that is far more efficient limiting when these are invoked.

urbansam

9:29 pm on May 10, 2010 (gmt 0)

10+ Year Member



Thanks for the help! I really appreciate it. Is there any way to solve the .shtml problem I mentioned?

g1smd

9:50 pm on May 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, I mentioned that in the first post.

You'll also need all the other fixes I mentioned.