homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Can't Get RewriteRule to Rewrite
Using . as a separator

 5:13 pm on Jun 25, 2008 (gmt 0)

I'm trying to create a more manageable URL for people. The dynamic URL would be in the form of:


The "easy" URL I want is:


Here is what I've tried:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^/([a-z]+)\.([a-z]+)$ http://www.example.com/index.php?name=$1.$2 [NC]
RewriteRule ^/(.*)\.(.*)$ http://www.example.com/index.php?name=$1.$2 [NC]
RewriteRule ^/([^/]+)\.([^/]+)$ http://www.example.com/index.php?name=$1.$2 [NC]

RewriteRule ^/([a-z]+)\.([a-z]+)$ /index.php?name=$1.$2 [NC]
RewriteRule ^/(.*)\.(.*)$ /index.php?name=$1.$2 [NC]
RewriteRule ^/([^/]+)\.([^/]+)$ /index.php?name=$1.$2 [NC]

None of these have worked. Is it not possible to use the . as a separator? I've seen other sites doing it, but maybe they're not doing it with htaccess.

[edited by: jdMorgan at 5:41 pm (utc) on June 25, 2008]
[edit reason] example.com [/edit]



 5:56 pm on Jun 25, 2008 (gmt 0)

Your fourth rule is correct for the stated purpose if the code is located in httpd.conf or conf.d.

If this code is for .htaccess, be aware that the path to the current .htaccess directory is always stripped from the URL-path examined by RewriteRule -- i.e. the path is "localized" to the .htaccess file's directory. So, if this is the case, you'll need to remove the leading slash from the RewriteRule pattern.

Using "." as a separator will work, as long as no RewriteRules are looking for the "." and treating what follows as a filetype, and as long as you don't have MultiViews (content negotiation) enabled, which would also treat the periods as filetype separators. (For this application, I would suggest using a hyphen or an underscore, just to 'future-proof' your URLs in case you do someday want to use either of these techniques.)

If you still wish to use a period as a separator, then you will also need to explicitly prevent the rewritten request for "index.php?name=firstname.lastname" from being subsequently rewritten to /index.php?name=index.php repeatedly -- in an 'infinite' rewrite loop. Typically, you could do this by adding a RewriteCond.

In example.com/.htaccess:

RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^([a-z]+)\.([a-z]+)$ /index.php?name=$1.$2 [NC]

Note that the leading slash *will* be present on the URL-path in REQUEST_URI in either httpd.conf, conf.d, or .htaccess, so don't remove it as a result of my comments pertaining to RewriteRule above.


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