Jump to content

[SOLVED] Mod Rewrite - dot


jaymc

Recommended Posts

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 ^([^/\.]+)/?$

Link to comment
https://forums.phpfreaks.com/topic/113569-solved-mod-rewrite-dot/
Share on other sites

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?

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

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]

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.