[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

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  ?
0
eranhazout
Asked:
eranhazout
  • 8
  • 7
1 Solution
 
Hatrix76Commented:
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
 
Hatrix76Commented:
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
 
Hatrix76Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
eranhazoutAuthor Commented:
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
 
Hatrix76Commented:
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
 
eranhazoutAuthor Commented:
it cause internal server error... when should I locate it ? before or after the rewrite rules?
0
 
Hatrix76Commented:
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
 
eranhazoutAuthor Commented:
just a standard internal server error ...
I'm using CentOS and Apache 2.2.3


0
 
Hatrix76Commented:
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
 
eranhazoutAuthor Commented:
[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
 
Hatrix76Commented:
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
 
eranhazoutAuthor Commented:
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
 
eranhazoutAuthor Commented:
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
 
Hatrix76Commented:
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
 
eranhazoutAuthor Commented:
hey, I don't know what changed but I guess you are right ...

it works fine ...

thank you very much .
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now