简体   繁体   中英

Rewrite URL Parameter containing dot

I think that I am trying to achieve an impossible result.

The scenario is PURL-Mailing and I already got some URL's rewritten to fit the URL, sent to the customer.

The customer enters the site by the following domain: http://domain.com/ UserName

The Variable UserName represents the GET-Variable, which equivalent to http://domain.com/index.php?user= UserName

I achieve this with the following rewrite Rules:

RewriteBase /

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?name=$1  [QSA] 
#This works perfect and translates to http://domain.com/UserName

RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?name=$1 [L] 
#This achieves the goal but does not reflect in the URI I want:
#http://domain.com/UserName

To go further, there are also some Names containing a dot in the Name like A.Jackson that also need to be treated as UserName . As those are only 13 Name I could implement them manually. What I don't know is how I can prevent the part after the dot to be handled as a file extension. Is there a way to write a custom handle in *mod_rewrite* for those? And if so, can anybody explain to me how?

Thanks in advance and best regards!

Here is your fix

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]*[\.]*[a-zA-Z0-9_-]+)$ index.php?name=$1  [L]

ok try below

RewriteCond %{REQUEST_FILENAME} !(img|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^([a-zA-Z0-9_-]*[\.]*[a-zA-Z0-9_-]+)[/]*$ test.php?name=$1  [L]

replace 'anyother folders that you want to ignore' with folder name that you want to ignore. Seperate each folders with '|'

You also have to provide full path to the CSS, image or any other links used in your web page when you using URL rewrite functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM