jaymc Posted July 7, 2008 Share Posted July 7, 2008 I have this rewrite rule RewriteRule ^([^/\.]+)/?$ index.php?open=my&user=$1 [L] This allows my website to have links like this www.site.com/usernamehere Works great, however, if the username as a fullstop in it, I get page cannot be displayed www.site.com/username.here Is there something wrong with the rewrite ^([^/\.]+)/?$ Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 7, 2008 Share Posted July 7, 2008 [^/\.] the ^ at the beginning, means anything EXCEPT for the characters listed. are you looking to allow numbers, letters, and periods? try this instead: ^([a-zA-Z\d\.]+)/?$ or if you want underscores too, you can shorten it to: ^([\w\.]+)/?$ Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 7, 2008 Author Share Posted July 7, 2008 That did not work The $1 was not being past I tried both your short and long versions Im begining to think there is a restriction on the dot for a reason with this? I want to allow anything Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 7, 2008 Share Posted July 7, 2008 Dot is not special when present inside a character class. Therefore if you want to match dot in a character class, use: [.] and not: [\.] Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 7, 2008 Share Posted July 7, 2008 where is my head....need the QSA switch... RewriteRule ^([\w.]+)/?$ index.php?open=my&user=$1 [QSA] Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 7, 2008 Author Share Posted July 7, 2008 That did not work either Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 8, 2008 Share Posted July 8, 2008 i am using this on my system and it works fine: RewriteEngine on RewriteRule ^([\w.]+)/?$ index.php?open=my&user=$1 [QSA] <?php print_r($_GET); ?> URL: http://hostname.com/test.acount produces output of: Array ( [open] => my [user] => test.account ) What does the above produce for you? What version of Apache are you running? Is this your server or with a hosting service? Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 8, 2008 Author Share Posted July 8, 2008 Wait, sorry! It did work, but with another problem When I use your code above, my style sheet wil not load. I have no idea why that would be effected? Here is the HTML head of my document <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <base href="http://www.site.com/" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Websitename</title> <link rel="stylesheet" href="style.css" type="text/css"> <script type="text/javascript" src="java/popup_ad.js"></script> <script type="text/javascript" src="java/global_ad.js"></script> </head> I hope you can help Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 8, 2008 Share Posted July 8, 2008 it is because anything with a combination of characters/numbers/underscores/periods is considered a username. Since style.css matches that, it thinks it's a username. You have two options: 1) Move the stylesheet into a directory (like css/style.js). This way it has a slash in the path, and won't match the Rewrite 2) Or, you can modify your htaccess to this instead. This will prevent the Rewrite from happening if it matches a real file. This is the way I recommend, but if someone creates an account called style.css, they won't be able to access it (it will just show them your style sheet) RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f [NC] RewriteCond %{REQUEST_FILENAME} !-d [NC] RewriteRule ^([\w.]+)/?$ index.php?open=my&user=$1 [QSA] Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 8, 2008 Author Share Posted July 8, 2008 Ah thats makes sense, problem is I have a few files such as .js etc so would have to move them around I dont mind using RewriteCond %{REQUEST_FILENAME} !-f [NC] RewriteCond %{REQUEST_FILENAME} !-d [NC] But if my web server is very busy and that is processed on every single page, will it add a bit of overhead.. Also, just to clear something up Does rewrite stuff work faster if added to APACHE CONF rather than a .htaccess file? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 8, 2008 Share Posted July 8, 2008 not really sure how that performance will scale...but i wouldn't worry about it. you are talking about about saving milliseconds, and chances are, your bottleneck will be in the PHP code and not here. Quote Link to comment Share on other sites More sharing options...
jaymc Posted July 8, 2008 Author Share Posted July 8, 2008 I just read apache manual for this Apache say never use .htaccess unless you have no access to apache conf as for every single page call it has to check for the .htaccess file in the root directory and every single parent directory I guess it adds up, although probably miliseconds still Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.