homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

htaccess wrong code ?
something strange

 3:01 pm on Nov 15, 2010 (gmt 0)

hello guys,
is this code correct?

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^http://www.sample.com/folio.html/ [sample.com...] [R=301,L]

RewriteRule ^http://www.sample.com/Residential.html/ [sample.com...] [R=301,L]


but this code doesn't work, where is a mistake?



 3:12 pm on Nov 15, 2010 (gmt 0)

Noximus --

The first parameter of the RewriteRule contains only the path info, not the fully qualified domain name.

If your RewriteRule is in the server configuration or a VirtualHost configuration, then the path will start with a /. If it is in a .htaccess file (more common, less desirable if you have the choice between the two) then the path will not start with the /. In the latter case, you'll also have to set RewriteBase.

Here's code for a server-base/virtual host context:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^/folio.html$ http://www.sample.com/Showcase.htm [R=301,L]
RewriteRule ^/Residential.html$ http://www.sample.com/Stones.htm [R=301,L]

In a .htaccess context it would be

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteRule ^folio.html$ http://www.sample.com/Showcase.htm [R=301,L]
RewriteRule ^Residential.html$ http://www.sample.com/Stones.htm [R=301,L]

The ^ means "starts with" -- a good practice to get into (you might, for example have a "Portfolio.html" page, which would also match :-). $ means "ends with".



 4:17 pm on Nov 15, 2010 (gmt 0)

Thank you very much, you helped me a lot.

good luck online and offline.


 3:22 pm on Nov 16, 2010 (gmt 0)

Note that literal spaces in the regular-expressions patterns should be escaped to avoid ambiguity.

In a server config file, outside of any <Directory> sections:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^/folio\.html$ http://www.example.com/Showcase.htm [R=301,L]
RewriteRule ^/Residential\.html$ http://www.example.com/Stones.htm [R=301,L]

- or -
In a .htaccess file, or within a <Directory> section in a server config file:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^folio\.html$ http://www.example.com/Showcase.htm [R=301,L]
RewriteRule ^Residential\.html$ http://www.example.com/Stones.htm [R=301,L]

It is also generally recommended that all URLs be specified as all-lowercase, to make URL canonicalization possible without having to resort to scripted solutions or to solutions which require CPU-intensive 'file-exists' checks.

Yes, mixed-case URLs can "look more attractive," but can lead to *major* headaches if people link to mis-cased URLs; If the correct URLs are always all-lowercase, this problem can be easily fixed simply by rewriting the mis-cased URL requests to all-lowercase. If the correct URLs are mixed-case, then the filesystem must first be searched to determine the correct casing, which is expensive in terms of server performance, and may be almost impossible without using a scripted approach to determine the 'most likely correctly-cased URL.' Certain combinations of URL-rewriting and mixed-case URL usage may in fact make this impossible to do, leading to lost business opportunity due to the visitors receiving 404-Not Found errors from mis-cased links.



 3:37 pm on Nov 16, 2010 (gmt 0)

To clarify Jim's comment, I failed to properly escape the . in the filename -- without being escaped the . means "a character". This character could be anything, and is probably a "." but could be a space, or any other character.

I strongly agree with Jim's advice to make URIs lowercase. The HTTP spec allows to domains to (www.example.com) to be delivered in any case, so any matching on domains should use the [NC] flag, however the path part of a URL is case sensitive. To avoid confusion, go with lower-case.


 3:54 pm on Nov 16, 2010 (gmt 0)

Thank you very much Jim.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved