Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite works offline, not online.

         

Fourjays

10:56 am on Aug 23, 2006 (gmt 0)

10+ Year Member



Hi,
I have spent the last few months developing my own website in php. I have been doing so on a quick server setup on my own computer (using XAMPP). When I started, I had another go at using mod_rewrite and successfully managed to figure it out! However, I have now got the script to the stage where it needs to go on my webserver. I have uploaded it, updated the database, etc, however the mod_rewrite refuses to work! I'm sure it is mod_rewrite, because if I type in the URLs manually (eg: index.php?q=blah&etc=foo) it brings up the correct page. If I use the one that needs to go through mod_rewrite (eg: index/blah/foo), it doesn't work.

I have checked a couple of things already; phpinfo() says mod_rewrite is loaded and a test I found on another website worked (RewriteRule /yahoo.me [yahoo.com)....] Another similar test also worked (RewriteRule /index [yahoo.com)....]

Yet my own rules will not work (which worked on the server run off my hard drive). Does it make any difference that my server is Windows, and the webserver is Linux?

Here are couple of my rules;


RewriteEngine on
RewriteRule ^index/?$ index.php [L]
RewriteRule ^index/sess/([^/\.]+)/?$ index.php?sess=$1 [L]
RewriteRule ^index/([^/\.]+)/?$ index.php?q=$1 [L]
RewriteRule ^index/([^/\.]+)/sess/([^/\.]+)/?$ index.php?q=$1&sess=$2 [L]

All of my rules are of the same structure, just with different values. If there something missing? Have I done something incorrectly? Any help and ideas are greatly appreciated.
Thanks

jdMorgan

12:00 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you get any error messages?
Anything in your server error log?
Where is the code located -- .htaccess or httpd.conf?

Two most likely causes:
1) Code in .htaccess may need to be preceded by


Options +FollowSymLinks

2) Code in httpd.conf requires a subtle syntax change; RewriteRule patterns should start with "/", e.g,

RewriteRule [b]^/in[/b]dex/?$ index.php [L]

Jim

Fourjays

12:15 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



Thanks for the reply.
No error messages in my error log relating to the mod_rewrite or htaccess. The code is located in a .htaccess file. I tried the "Options +FollowSymLinks" one earlier, but that made no difference. Just tried your second idea and that didn't work either.

However, I have got somewhere.

I am operating in a sub-domain (although I tried it on a www. too and the same happened). Anyway, I visit {url}/index/join which should redirect to index.php?q=join. Now after some testing, I managed to get it to work when I left off the index/ on the rewriterule. ie:


RewriteRule join/?$ index.php?q=join [L]

Then it works fine. It seems to be skipping the first part. I can't do this though, as another rule uses that first part with a variable in. ie:


RewriteRule ([^/\.]+)/?$ artlog.php?title=$1 [L]

How do I stop it skipping the first part? I've been looking at RewriteBase, but I have no idea what I would need to do with it exactly to get it to read the first part as well.

[edited by: Fourjays at 12:15 pm (utc) on Aug. 23, 2006]

jdMorgan

1:18 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> The code is located in a .htaccess file.

At what directory level? The .htaccess file is a "per-directory" configuration file. Therefore, if this code is located *in* /index/, then that part of the patch will be stripped off (for security reasons), and RewriteRule will never see it. You will need to move your code to the Web root directory (above /index/) in order for it to be able to test for "/index".

At any rate, this sounds like a problem related to the location of the code, rather than any basic functionality problem, and that's good news.

Jim

Fourjays

1:41 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



Ok, got you.

Well I'm operating on a sub-domain (artlog.example.net), so all the files (index.php, download.php, etc) are directly in that folder (public_html/artlog), including the .htaccess. I've tried to illustrate the structure below (tried being the key word). There isn't a index folder, but some other folders like /includes, /templates and /images. None of which have an .htaccess in them.

public_html
- artlog
- - .htaccess
- - index.php
- - download.php
- - etc...

Thanks for your continued help.

[edited by: jdMorgan at 2:15 pm (utc) on Aug. 23, 2006]
[edit reason]
[1][edit reason] Examplified [/edit]
[/edit][/1]

jdMorgan

2:15 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have no /index/ subdirectory, then what is the meaning of "index" in your /index/join example above?

A path-part can be a file or a directory, but not bothat the same time.

I am thinking maybe you've got an interaction here between a DirectoryIndex directive and your rules... Do you have a DirectoryIndex directive in .htaccess or httpd.conf? If so, what does it say?

Jim

Fourjays

2:26 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



The index in the index/join example is refering to index.php. Basically, the end result is supposed to be index/join the same as index.php?q=join. As another example; blah.com/browse/art/all/all/date would be the same as blah.com/browse.php?b=art&filter1=all&filter2=all&sort=date.

I don't have a DirectoryIndex directive in .htaccess. All there is in my .htaccess is "Rewrite Engine on" followed by the rules. I'm not sure about httpd.conf. I can't access it on the webserver (that I can see), as I'm on a shared hosting account (I'll ask my host when I next talk to him).

Fourjays

3:24 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



Managed to fix it. :D

Found this (http://www.webmasterworld.com/forum92/2282.htm) after another hour of searching on Google. I read through it, and it seemed similar. So I tried what Garfield did (blah/join to index.php?q=join) and it worked fine. So I then added the option you (jdMorgan) suggested in the thread, of adding "Options -MultiViews" to the top, and it all seems to be working fine. :D

Such a short line fixes such a strange problem...

Thanks for all your help jdMorgan, and the advice posted in the other thread. :)