Solved

Rewrite Rule

Posted on 2010-11-14
15
410 Views
Last Modified: 2012-05-10
I have a rewrite rule for www.domain.com/user-name to
www.domain.com/profile.php?n=user-name

and second rule for www.domain.com/pro-p/user-name point to
www.domain.com/small-profile.php?n=user-name

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^pro-p/([a-zA-Z0-9-_]+)/?$ small-profile.php?n=$1 [L]
RewriteRule ^([a-zA-Z0-9-_]+)/?$ profile.php?n=$1 [L]


since I created these rules I can't go to real directories such as domain/admin and doamin/newsletter
etc' ... the rule send me directly to profile.php

any ideas  ?
0
Comment
Question by:eranhazout
  • 8
  • 7
15 Comments
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34131556
I'm sorry, but this is a peculiar situation. If the usernames have a specific format you may be able to parse a pattern, but if they are more like realnames than there is no way to distuingish them from the directories.

So you have to exclude the real directories from rewriterules like:

directly after the RewriteEngine on add this:

  #
  # stuff to let through (ignore)
  RewriteCond %{REQUEST_URI} "/folder1/" [OR]
  RewriteCond %{REQUEST_URI} "/folder2/"
  RewriteRule (.*) $1 [L]

You can add more folders with [OR], but the last folder without, these excludes this folders from being rewritten.

best
Ray
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34131681
Thinking of it, there might be another solution, but I have not tested it.

As .htaccess files take precedence over configurations in the config files, try to add:

RewriteEngine off

in a .htaccess in each of the real directories you have.

It might be an easier solution, but either way, you have to remember that additional configuration changes are necessary when adding more directories.

best
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34131741
Hmm, after further thinking about it ... forget what I said, I'm to tired to write answers today :-)

I guess your real problem is that, contrary to the documentation, %{REQUEST_FILENAME} is not really the full systempath, but rather it is a relative path to the document-root, so try to change your config into:


RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^pro-p/([a-zA-Z0-9-_]+)/?$ small-profile.php?n=$1 [L]
RewriteRule ^([a-zA-Z0-9-_]+)/?$ profile.php?n=$1 [L]

So it should exclude all physical files and directories from the rewriterules ...

best
Ray
0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

Author Comment

by:eranhazout
ID: 34135030
Hi

sorry for the delay ...
I have tried your last rules, exactly as you wrote ... and still can't go to physical directories ...

Thank you
Eran
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34135095
Can you turn on rewrite debugging and attach a log:



RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 3


keep in mind that this slows down the server, so take the commands out if you have a log report!

best
0
 

Author Comment

by:eranhazout
ID: 34135141
it cause internal server error... when should I locate it ? before or after the rewrite rules?
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34135184
what exactly was the internal server error? Normally after the RewriteEngine on is sufficient.

But the order should really not matter, btw. which operating system do you use and which version of apache?

best
0
 

Author Comment

by:eranhazout
ID: 34135235
just a standard internal server error ...
I'm using CentOS and Apache 2.2.3


0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34135260
can you paste the messages from the error log file (I am not sure where it is on centos, I believe it's /var/log/httpd/error.log, or the log file you defined in a virtual host if you redefined it.).

In this file should be detailed error messages regarding the internal error.

best
Ray
0
 

Author Comment

by:eranhazout
ID: 34135793
[Mon Nov 15 13:12:45 2010] [warn] [client 192.168.1.102] mod_include: Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed, referer: http://www.gurushots.info/
[Mon Nov 15 15:04:06 2010] [alert] [client 192.168.1.102] /home/photo/public_html/.htaccess: RewriteLog not allowed here, referer: http://www.gurushots.info/
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34135920
ok, this server is not under your control? I mean, is it a hosted solution? It seems you are not allowed to write a rewritelog in /tmp, try to write the rewritelog to:

/home/photo/public_html/rewrite.log

best
0
 

Author Comment

by:eranhazout
ID: 34136034
the same problem ...

[Mon Nov 15 15:43:59 2010] [alert] [client 192.168.1.102] /home/photo/public_html/.htaccess: RewriteLog not allowed here, referer: http://www.gurushots.info/
0
 

Author Comment

by:eranhazout
ID: 34136243
Hi

the rule is working well .
but now when I'm trying to go to www.doamin.com/admin/ it shows www.doamin.com/admin?n=admin

this is the rules i have right now:

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.gurushots.info/$1 [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pro-p/([a-zA-Z0-9_-]+)/?$ /pro-profile.php?n=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /pro-full-profile.php?n=$1

thank you
0
 
LVL 7

Accepted Solution

by:
Hatrix76 earned 500 total points
ID: 34136307
when I go to:

http://www.gurushots.info/admin

it works fine, i get the url fine like this in the browser: http://www.gurushots.info/admin/ and I got an admin login page, seems it's working fine from where I am ...

best
0
 

Author Comment

by:eranhazout
ID: 34136346
hey, I don't know what changed but I guess you are right ...

it works fine ...

thank you very much .
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question