[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Rewrite Rule

Posted on 2010-11-14
15
Medium Priority
?
432 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 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