Solved

Rewrite Rule

Posted on 2010-11-14
15
380 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now