|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| 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
|
||||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
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
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 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 |
|
||||
|
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. |
|
||||
|
thanks wige...
__________________
Join free dating sites and meet single people without paying a penny. |
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
Quote:
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. |
|
||||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
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 |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |