help on modrewrite problem

Started on the old forum in July 2013 · view the original in the archive · old links redirect here

13 replies · 1,224 views · started 13 years ago · 1 min read

5 participants
Junkle Junior · 21 posts #1

hi friends, am modrewriting my user profile url. Iz nw 'www.mysite.com/username' with that url u can acces user profile direct. But the problem am facing is that if a user UserName Contain '.' eg. 'Www.mysite.com/junkle.junk' it will not open rather its sh0wing me page n0t f0und. Pls hw do i ge rid of it . Tanx

Junkle Junior · 21 posts #3

Thiz iz my full .htacess file c0de:

<IfModule mod_rewrite.c>

RewriteEngine On

Options -Indexes

Options +FollowSymlinks
RewriteRule ^(.*)\.html$ $1.php [nc]

RewriteRule ^([a-zA-Z0-9_-]+)$ userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ userinfo.php?user=$1 [L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^[url=http://www.mysite.com]Website Hosting - Mysite.com[/url]
RewriteRule (.*) http://mysite.com/$1 [R=301,L]

# proc/self/environ? no way!
RewriteCond %{QUERY_STRING} proc/self/environ [OR]

# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]

# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]

# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]

# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]

# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})

# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]

</IfModule>
arnage Lead · 811 posts #4

This?

RewriteRule ^([a-zA-Z0-9_-\.]+)$ userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_-\.]+)/$ userinfo.php?user=$1 [L]
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Junkle Junior · 21 posts #5

whats wrong with that...

arnage Lead · 811 posts #6

I hope nothing... 😉 Change those two lines in your htaccess file like i wrote and try.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Junkle Junior · 21 posts #7
RewriteRule ^([a-zA-Z0-9_-\.]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_-\.]+)/$
 userinfo.php?user=$1 [L]

i did that but i got an eror..

RewriteRule ^([a-zA-Z0-9_\-\.]+)$ userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_\-\.]+)/$ userinfo.php?user=$1 [L]

that 0ne affect all my page saying user n0t found. Even with this bel0w

RewriteRule ^([a-zA-Z0-9-.]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9-.]+)/$
 userinfo.php?user=$1 [L]

and

RewriteRule ^([a-zA-Z0-9_.]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_.]+)/$
 userinfo.php?user=$1 [L]
something else Fellow · 2,296 posts #8

if you want any letters or symbols to be matched as a user name use:

RewriteRule ^.*$ userinfo.php?user=$1 [L]

by limiting the match to only: a-z A-Z 0-9 _ - . it is not matching against anything with / in the username - or alternatively you can add the forward slash into the matched symbols: a-zA-Z0-9_-./ just remember to write rules to make sure folders like /images/ are still accessible and you may want to block users from using your folder names in your script also.

Junkle Junior · 21 posts #9

S0mthing else so how do u intend me to apply the code n0W? I tried the fell0wing but was n0t w0rking...

RewriteRule^.*$userinfo.php?
user=$1[L]
RewriteRule ^([a-zA-Z0-9_\-\.\/]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9-\_\.\/]+)/$
 userinfo.php?user=$1 [L]

and

RewriteRule^.*$userinfo.php?
user=$1[L]
RewriteRule ^([a-zA-Z0-9_-]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9-_]+)/$
 userinfo.php?user=$1 [L]

and

RewriteRule ^([a-zA-Z0-9_\-\.\/]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9-\_\.\/]+)/$
 userinfo.php?user=$1 [L]
something else Fellow · 2,296 posts #10

Try adding a second directory into the rule (this will save you having to rewrite for every file/directory) eg:

yoursite.con/directory/yourName

RewriteRule ^ /directory/.*$ userinfo.php?user=$1[L]

also make sure you don't add the original 2 rules as they will trash this rule >.<

I know its not exactly as you want it but it will save your site from running slow from following to many rules, the only other option is to do a string replacement on the symbol "/" in your php script to replace it with something else to get round the forward slash problem 🙂

arnage Lead · 811 posts #11

Junkle wrote:

RewriteRule ^([a-zA-Z0-9_-\.]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_-\.]+)/$
 userinfo.php?user=$1 [L]

i did that but i got an eror..

RewriteRule ^([a-zA-Z0-9_\-\.]+)$ userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_\-\.]+)/$ userinfo.php?user=$1 [L]

that 0ne affect all my page saying user n0t found. Even with this bel0w

RewriteRule ^([a-zA-Z0-9-.]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9-.]+)/$
 userinfo.php?user=$1 [L]

and

RewriteRule ^([a-zA-Z0-9_.]+)$
userinfo.php?user=$1 [L]
RewriteRule ^([a-zA-Z0-9_.]+)/$
 userinfo.php?user=$1 [L]

Did you change the links in page?

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
funtowap Developer · 59 posts #12

Dude Use this one

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /user.php?username=$1 [L]

Use this code for it in your .htaccess of home directory

this will first check for if any folder with name exist there / any url exist e.g. yoursite.com/contact_us

this is not user so if any directory exist it will give it more priority, else it will proceed to your user page.

Was Just Out of site WORLD ..... Coming BACkkkkkkk.....

Junkle Junior · 21 posts #13

funtowap wrote: Dude Use this one

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /user.php?username=$1 [L]

Use this code for it in your .htaccess of home directory

this will first check for if any folder with name exist there / any url exist e.g. yoursite.com/contact_us

this is not user so if any directory exist it will give it more priority, else it will proceed to your user page.

thanx man. I used your idea to do s0mething like this

RewriteEngine On 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ userinfo.php?user=$1 [L]
RewriteRule ^([^/]*)/$ userinfo.php?user=$1 [L]

and its works as i wanted. But its still treating f0lders in my home directory as username whereby telling me, username n0t f0und. But only works for three f0lders and i observed that those three folderz are f0lderz that c0ntain .htaccess file in it. What could be the issue here...

funtowap Developer · 59 posts #14

Junkle wrote: thanx man. I used your idea to do s0mething like this

RewriteEngine On 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ userinfo.php?user=$1 [L]
RewriteRule ^([^/]*)/$ userinfo.php?user=$1 [L]

and its works as i wanted. But its still treating f0lders in my home directory as username whereby telling me, username n0t f0und. But only works for three f0lders and i observed that those three folderz are f0lderz that c0ntain .htaccess file in it. What could be the issue here...

Sorry? i didnt get your problem this time 😀

Was Just Out of site WORLD ..... Coming BACkkkkkkk.....

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close