Avatar of eranhazout
eranhazout asked on

Rewrite Rule

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  ?
Apache Web ServerLinux

Avatar of undefined
Last Comment
eranhazout

8/22/2022 - Mon
Hatrix76

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
Hatrix76

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
Hatrix76

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
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
eranhazout

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
Hatrix76

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
ASKER
eranhazout

it cause internal server error... when should I locate it ? before or after the rewrite rules?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Hatrix76

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
ASKER
eranhazout

just a standard internal server error ...
I'm using CentOS and Apache 2.2.3


Hatrix76

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
eranhazout

[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/
Hatrix76

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
ASKER
eranhazout

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/
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
eranhazout

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
ASKER CERTIFIED SOLUTION
Hatrix76

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
eranhazout

hey, I don't know what changed but I guess you are right ...

it works fine ...

thank you very much .