iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Webmaster Resources Discussion Forum Sitemaps and robots and logfiles -- Oh My! If you have any questions, comments, concerns and/or ideas about the tools currently available to webmasters to make their lives... 'easier'. Here's where you need to be. Know of a good tool? Post it here. Got something funny in your logfiles? Maybe we can help.

Share Thread: & Tags

Share Thread:

Tags
htaccess compatibility

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-12-2009, 03:59 PM
Silverback's Avatar
WebProWorld Member
 
Join Date: Mar 2008
Location: Canada
Posts: 28
Silverback RepRank 1
Default htaccess compatibility

I am changing over a general shopping site to a proper directory and have a question regarding the .htaccess file.

Although all but three sub folders will be deleted. there are a few pages that I would like redirected to other sites simply as a 301 redirect statement in the htaccess file. Rather than jumping in and making assumptions I thought I should ask the pros whether there is going to be the compatibility issue.

The following is an excerpt of the new .htaccess file that will sit in the top file

Code:
#################################################
## PHP Link Directory - Apache Server Settings ##
#################################################

# Prevent .htaccess and .htpasswd files from being viewed by web clients
<Files "^\.ht">
    Order allow,deny
    Deny from all
</Files>

# Protect files
<Files ~ "^(.*)\.(inc|inc\.php|tpl|sql)$">
  Order deny,allow
  Deny from all
</Files>

# Protect directories
<Files ~ "^(backup|files|images|include|lang|libs(/.+)?|temp(/.+)?|templates(/.+)?|javascripts(/.+)?)$">
  Order deny,allow
  Deny from all
</Files>

# Disable directory browsing
Options -Indexes

# Follow symbolic links in this directory
Options +FollowSymLinks

# Override PHP settings that cannot be changed at runtime
# (If your server supports PHP settings via htaccess you can comment following two lines off)
# php_value register_globals   0
# php_value session.auto_start 0

# Customized error messages
# ( If you are running in a subfolder please add it, example: "directory/index.php?httpstatus=404" )
ErrorDocument 404 index.php?httpstatus=404

# Set the default handler
DirectoryIndex index.php

# URL rewrite rules
<IfModule mod_rewrite.c>
   RewriteEngine On
As indicated that is not the full extent of the file

What I was planning on doing was adding basic redirect as follows:

Code:
301 redirect /folder1.html http://www.siteurl.com/folder1.php
301 redirect /folder2.html http://www.siteurl.com/folder2.php
301 redirect /folder3.html http://www.siteurl.com/folder3.php
AND-

Based on this statement included in the above "ErrorDocument 404 index.php?httpstatus=404" I presume that any pages that have been deleted will go to the main index?

So the question simply, is will joining the simple redirect statements to the above htaccess file work, or will this present a problem for search engines or my server?

Many thanks
SB
__________________
Women's Web DirectoryHuman Edited Directory exclusively for Today's Woman

Last edited by Silverback; 07-12-2009 at 04:01 PM. Reason: correction
Reply With Quote
  #2 (permalink)  
Old 07-12-2009, 09:12 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,661
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: htaccess compatibility

Looks pretty good from a technical standpoint, although I see a couple possible improvements.

First, the error doc. If you are taking users to the index page, and just changing a bit of the text, you could have a duplicate content issue. Also, Yahoo has problems crawling sites that use the home page as the 404 message. You might be better off serving a completely customized page on 404 errors.

Next, for the folders that you deny access to, there is an alternative that might be more secure. Although you deny access through .htaccess, if a script on your site can be compromised to read files, you are telling hackers that there is something there that is sensitive. However, you can easily hide these files so that nobody can tell they even exist. Remove the <file> section, and replace it with
"RedirectMatch 404
^(backup|files|images|include|lang|libs(/.+)?|temp(/.+)?|templates(/.+)?|javascripts(/.+)?)$"
(without the quotes) This will cause the server to return the default 404 message when any file in that folder is requested, whether it exists or not.

Finally, the Redirects look good, but if you are redirecting entire folders, RedirectMatch might be better... RedirectMatch 301 ^/folder/(.*)$ http://site.tld/newfolder/$1
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #3 (permalink)  
Old 07-13-2009, 05:25 PM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,011
morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5
Default Re: htaccess compatibility

well ok wige, you DO seem to be pretty apt. at .htaccess files and I think I asked you this once before, I'm not sure but...

is there anyways in hell you can see, that via .htaccess I can make the following URL cleaner?

a-domain.com/?L=users.profile&id=5095
__________________
Join free dating sites and meet single people without paying a penny.
Reply With Quote
  #4 (permalink)  
Old 07-13-2009, 05:52 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,661
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: htaccess compatibility

That would be done with mod rewrite. I'll try to post the code tomorrow.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #5 (permalink)  
Old 07-14-2009, 10:26 AM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,011
morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5
Default Re: htaccess compatibility

Quote:
Originally Posted by wige View Post
That would be done with mod rewrite. I'll try to post the code tomorrow.
thanks wige...
__________________
Join free dating sites and meet single people without paying a penny.
Reply With Quote
  #6 (permalink)  
Old 07-14-2009, 11:22 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,661
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: htaccess compatibility

Ok, the first thing you need to do is come up with the search engine friendly URL. I am guessing that the url you showed has the purpose of showing the user profile for user 5095. A nicer URL than a-domain.com/?L=users.profile&id=5095 would be a-domain.com/profiles/user-5095.php. That is what we will be converting to the URL that you gave. Basically, you would link to the /profiles/ URL, and that is what users will see, but the server will see the URL as actually being L=... Bear in mind, this will kind of require that the /profiles/ folder not already exist, because requests for that folder might get messed up as a result of this rule. This is the code to accomplish this:

RewriteEngine on
RewriteRule ^/profiles/user-([0-9]+)\.php$ /?L=users.profile&id=$1 [L]

In this example, I am making the assumption that all user ids are numeric (as indicated by the [0-9]), and are at least one digit long (indicated by the plus sign). The $1 in the string the request gets translated into will be replaced by the contents of the first set of parenthesis in the string that represents the requested URL.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #7 (permalink)  
Old 07-14-2009, 11:28 AM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,011
morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5
Default Re: htaccess compatibility

you always kick ass wige really...you always seem to give great help...

ok i don't have access to my account from here but i'll be throwing this in tonight and will get back to you...and thanks for the explanation of the code, for instance the plus sign...

so with the plus sign, you're saying that the digit has to be at least one digit long...and if you wanted to you could not add the plus sign there right?

OK I think I got it...I'll get back to you shortly...I love mod-rewrite...
__________________
Join free dating sites and meet single people without paying a penny.
Reply With Quote
  #8 (permalink)  
Old 07-14-2009, 12:14 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,661
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: htaccess compatibility

If the plus sign is not there, it would only match a single digit. This is a shortcut for specifying how many digits there are. The long way is using braces to indicate a minimum and maximum number of digits.

[0-9]{3} - A number three digits long.
[0-9]{1} - A number one digit long. Since [0-9] automatically matches 1 digit, you could leave off the {1} and just have [0-9]
[0-9]{1,} - At least one digit. This is the same as [0-9]+
[0-9]{0,1} - There might be a digit, or there might not. This is the same as [0-9]?
[0-9]{0,} - There might be a digit, there might not, or there might be a lot of digits. This is the same as [0-9]*

Notice that an unlimited maximum number of digits is indicated by not entering a number after the comma.

I should point out that regular expressions, which is what these patterns are called, are one of the higher level aspects of programming. Even a lot of professional programmers have problems with them. There is a really good website that has a library of regular expressions as well as a test utility and references at http://regexlib.com/, which you might find helpful. If you use Firefox, there is also an addon for creating and testing regular expressions to make sure they do what you expect. https://addons.mozilla.org/en-US/firefox/addon/2077
__________________
The best way to learn anything, is to question everything.

Last edited by wige; 07-14-2009 at 12:18 PM.
Reply With Quote
  #9 (permalink)  
Old 07-14-2009, 12:25 PM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,011
morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5
Default Re: htaccess compatibility

nice! and once again wige, thanks...I'm going to bookmark http://regexlib.com

I'll get back to you later on my results...
__________________
Join free dating sites and meet single people without paying a penny.
Reply With Quote
  #10 (permalink)  
Old 07-15-2009, 12:01 AM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,011
morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5
Default Re: htaccess compatibility

Quote:
Originally Posted by wige View Post
Ok, the first thing you need to do is come up with the search engine friendly URL. I am guessing that the url you showed has the purpose of showing the user profile for user 5095. A nicer URL than a-domain.com/?L=users.profile&id=5095 would be a-domain.com/profiles/user-5095.php. That is what we will be converting to the URL that you gave. Basically, you would link to the /profiles/ URL, and that is what users will see, but the server will see the URL as actually being L=... Bear in mind, this will kind of require that the /profiles/ folder not already exist, because requests for that folder might get messed up as a result of this rule. This is the code to accomplish this:

RewriteEngine on
RewriteRule ^/profiles/user-([0-9]+)\.php$ /?L=users.profile&id=$1 [L]

In this example, I am making the assumption that all user ids are numeric (as indicated by the [0-9]), and are at least one digit long (indicated by the plus sign). The $1 in the string the request gets translated into will be replaced by the contents of the first set of parenthesis in the string that represents the requested URL.
wigi, i hate to do this man but it just didn't work - i thought it would give me a server error or something to but nothing actually changed or happened. I tried revising the string a tad but to no avail.

I have the .htaccess file in the root directory...the site is created with the smarty engine - could that be the issue? as in might the .htaccess file need to be in another directory?

Also, there is no /profiles/ dir just to let you know so that can't be causing a problem.
__________________
Join free dating sites and meet single people without paying a penny.
Reply With Quote
  #11 (permalink)  
Old 07-15-2009, 10:39 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,661
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: htaccess compatibility

No worries, it doesn't always work on the first try - often need to do a little tweaking to get everything working right. First off, the root .htaccess file is where the directive should be.

When you go to http://domain.tld/profiles/user-1234.php what do you get? Does this url stay in the address bar or does it get changed? Do you get an error message or a blank page?

There are a couple possibilities. Based on your statement that nothing happened, I am going to assume that entering the url caused you to get a blank page (if so, could you post the source code of the blank page?) which generally means that the PHP script encountered a fatal error, and your server is configured to in such a way that these errors are not displayed to the user.

Generally, this will happen because the REQUEST_URI variable changes as a result of the redirection. It is not common, but sometimes scripts will check this value. In the case of a prebuilt shopping cart, it might not be something you want to muck around with too much to try to fix.

Another possibility is that the redirect just didn't take. Try changing the /?L=users.profile&id=$1 to the URI of an image on the site. This should give us a way to confirm that the mod_rewrite engine is actually working and being triggered correctly.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Webmaster Resources Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IE8 and its 'Compatibility View' Ricardo Zea Graphics & Design Discussion Forum 28 06-18-2009 02:27 PM
CSS browser compatibility chart Conficio Graphics & Design Discussion Forum 2 05-31-2004 10:09 PM
Vl-design: browse compatibility vldesign Graphics & Design Discussion Forum 2 05-07-2004 01:55 PM
Compatibility wmabear54 IT Discussion Forum 4 04-07-2004 10:51 AM
Mac compatibility trippleweb Graphics & Design Discussion Forum 1 03-29-2004 07:09 PM


All times are GMT -4. The time now is 01:26 PM.



Search Engine Optimization by vBSEO 3.3.0