简体   繁体   中英

htaccess rewrite condition and rewrite rule for redirecting to a page using a particular name having peroids

I have a link http://mysite.com/username which redirects to profile page of current

username..

My htaccess code for this link is :

RewriteCond %{REQUEST_URI} ^/(\w+)/?$ [NC]
RewriteRule ^ profile.php?username=%1 [L,QSA]

But my problem is if username conatains periods(.) this condition wont work..

eg: if link is http://mysite.com/user.name , it shows not found page..

I want to allow only periods in username, no need of hyphen or underscores...

How can i check it using htaccess?

Someone help me plz....

Change your RewriteRule code to this:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([\w.]+)/?$ profile.php?username=$1 [L,QSA]

Also keep in mind that underscore is already included by using \\w in your regex.

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