Mod_rewrite

mallaire

Verified User
Joined
Jul 5, 2003
Messages
28
Location
Montreal, Canada
I know this problem may not be related to DA, but I didn't found anything on this...

Does anyone know why the mod_rewrite engine allow me to see the rewritten URL, but my PHP file can't see the value that has been rewritten.

Example:

Original URL: http://domain.com/view.php?id=5
Rewritten URL: http://domain.com/view/5 (the page is showing, but the id value is not getting through it).

My htaccess is composed of:
RewriteEngine ON
RewriteRule ^view\/(.*)/?$ view.php?id=$1

Please help... :confused:

Thank you!
 
I'm having the same problem using Apache 1.3 with DirectAdmin.

SIMPLE examples from the Apache howto don't even work. DirectAdmin support: there's a serious problem here.

The URL's will translate, but the arguments ($1, $2, etc) will NOT. I've had about a half dozen Apche guru's look at it, and they insist something is malfunctioning. I mean...I'm pasting code that has worked on 2 other servers, and I can't get even BASIC mod_rewrite rules to work.

If I do the default httpd.conf and run it on an odd port, things work fine. But with DirectAdmin involved, it's....less than perfect in translation.

Anybody else had trouble with this?
 
Last edited:
Have you tried to add [R,L] at the end of the RewriteRule statement?
Code:
RewriteRule ^view\/(.*)/?$ view.php?id=$1 [R,L]
 
I have tried, and it's not working....

[R] (force Redirect)
Redirect the URL to a external redirection. Send the HTTP response, 302 (MOVED TEMPORARILY).

[L] (last rule)
Forces the rewriting processing to stop here and don't apply any more rewriting rules.

-------

I think it is a problem with DirectAdmin... do you know someone else with the same config that could try it?
 
I have tried 2 different ways to achieve this that worked...

This is the first (note the slash before view.php):
Code:
RewriteRule ^view/([0-9]+)  /view.php?id=$1 [R,L]

This is the second method:
Code:
RewriteCond %{REQUEST_URI}  ^/view/([0-9]+)$
RewriteRule .*  /view.php?id=%1 [R,L]
The difference is the way it uses the variable. The first one uses $1, which gets the token from RewriteRule. The second one uses %1, which gets the token from RewriteCond.
 
I'm having a similar problem as mallaire. Except that in my case, now i've removed the .htaccess from the directory to remove the rules, yet it still does it! I've made the rewrite engine set to off in this ,htaccess file and still no go!

I've even changed what the rewriterule is for this folder and still it reverts to the old way! I check the main httpd.conf and the one for the site..nothing there...but the rewrite is still being done. I added a RewriteLog line in the main httpd.conf and nothing shows up there either for this idrectory..im flabbergasted!

RewriteEngine ON
RewriteRule ^/view/(.*) /path/to//public_html/dir/view.php [E=id:$1]

this should work right? if i want domain.com/view/01 to take mt o view.php with variable $id
 
I had to bought a new server... so I have installed a brand new machine.... I've installed a new DirectAdmin license... and I still have the same problem with Mod_Rewrite.

I don't know where.... but DirectAdmin is hiding a RewriteRule somewhere in the main settings. This rule overwrite all the other ones....

I cannot even turn the Rewrite engine off in the .htaccess.... and not a simple rule is working.

All the suggestions made above are working on my local "dev" server... but not on my DirectAdmin server.

PLEASE HEEEELP!!!! :confused: :confused:
 
This thread is not what I expected to find after 2 days of troubleshooting and tarring off our running sites.

Our code runs across 6 different servers over several years. We've ran on as many different versions of Apache and multiple operating systems and never experienced this problem until we put it on DirectAdmin.

The following is a code snip that no longer works:
RewriteRule forecast/([0-9]+) forecast.php?forecast=zandh&pands=$1
RewriteRule forecast/([^/.]+)/([^/.]+)_([^/.]+)_([^/.]+)_([^/.]+)_([^/.]+) /forecast.php?forecast=zandh&pands=$2+$3+$4+$5+$6+$1
RewriteRule forecast/([^/.]+)/([^/.]+)_([^/.]+)_([^/.]+)_([^/.]+) /forecast.php?forecast=zandh&pands=$2+$3+$4+5+$1
RewriteRule forecast/([^/.]+)/([^/.]+)_([^/.]+)_([^/.]+) /forecast.php?forecast=zandh&pands=$2+$3+$4+$1
RewriteRule forecast/([^/.]+)/([^/.]+) /forecast.php?forecast=zandh&pands=$2+$1
RewriteRule forecast/([^/.]+)_([^/.]+)_([^/.]+)_([^/.]+) forecast.php?forecast=zandh&pands=$1+$2,$3,$4
RewriteRule forecast/([^/.]+)_([^/.]+)_([^/.]+) forecast.php?forecast=zandh&pands=$1,$2,$3
RewriteRule forecast/(.*) /$1

The problem is wiith "forecast="
We can change the word forecast to anything else, including Forecast, and it will work, but not with forecast. I'm not sure if there are other problems, but not having mod_rewrite work with DA is a show stopper. I'm glad we found it before we put other sites on it.

It's difficult to imagine the interaction between a control panel and mod_rewrite, but there is. It is also why I was late in coming here. We even had another control panel on the same server before reloading DirectAdmin, and it worked fine.

Ths is really too bad. I see no fixes on this thread or the others I've looked at so I'm assuming there is no fix and I will need to move off from DA unless I hear different.

Thanks!
 
PS: I am running an out-of-the-box install, latest version, on FreeBSD 6.0. We made no changes to any of the modules.
 
DA makes no changes to how mod_rewrite works.

I don't know why or how forecast could be a reserved word, but I'm bringing the post to the attention of DA support staff.

Jeff
 
Problem still not fixed

I am still unable to get my mod_rewrite rules working... does anyone found a solution? I've tried all the alternatives (other ways of coding the rules), and it still don't work.
 
Hello,

I may have found it.

Edit /etc/httpd/conf/httpd.conf

Edit
Code:
<Directory /home/*>
    AllowOverride All
    Options [b]MultiViews[/b] -Indexes FollowSymlinks IncludesNoExec +Includes
and replace it with
Code:
<Directory /home/*>
    AllowOverride All
    Options [b]-MultiViews[/b] -Indexes FollowSymlinks IncludesNoExec +Includes
Let me know if that's what you're looking for. If so, I'll make the change permanent.

That's the only real place that can do it, other than directly in the users httpd.conf file. There are no mystery hidden .htaccess files, that would be cruel to admins ;)

John
 
Let me know if that's what you're looking for. If so, I'll make the change permanent.
From every indication that I have so far, that fixed the problem. The code that failed 100% of the time before the change, I have not been able to make fail since the change.

Thanks!
 
Last edited:
Same here

Finally after months of thinking I could never master .htaccess, it transpires I was doing the right thing. Just a small server setting fixed everything.
:)
 
Back
Top