views:

38

answers:

2

I thought I could do this with rewrite but I can't seem to find any information on it. What I want to do is this.

/path/to/my/program/index.php

I want to use a link for the use such as.

/forum/index.php

Is this posible?

A: 

Try this in your .htaccess file:

RewriteEgnine on
RewriteRule ^forum/(.*) path/to/my/program/$1 [L]

That will rewrite any request that’s URL path starts with /forum/… to the same but starting with /path/to/my/program/….

Gumbo
Thank you Gumbo. Let me give that a try. brb.
Jim
@Jim: If your path is an absolute file system path, use it with the leading slash.
Gumbo
No Gumbo, nothing.. It doesn't work. I checked the path twice and it is correct.
Jim
Yep, I already tried that. Both ways does nothing
Jim
@Jim: And mod_rewrite is available on your server?
Gumbo
Yes. I'm using it already with a couple of other rules. Its really weird because I commented out what I already had in the htaccess file and just left yours in and it will not work. I did just now manage to get it working with apache's alias directive BUT... I'd rather use mod_rewrite if possible. Would you have any idea why this isn't working?
Jim
@Jim: Where do you use that rule?
Gumbo
You mean the rule for the forum? I have it in the htaccess file in the directory root. Is that what you meant?
Jim
Gumbo, I noticed something... Maybe I'm wrong but shouldn't there be a dollar sign after the closing paran? Like this: ^forum/(.*)$
Jim
@Jim: No, in this case there is no difference whether you specify the end of the URL path or not. `.*` will match everything up to the end.
Gumbo
Ah, ok.. Thanks. Well, what do you think? Should I just stay with the Alias directive or do you think there is still hope to get this working with mod_rewrite?
Jim
@Jim: Why not if it works.
Gumbo
Ok, thanks for all the help! I really appreciate it.
Jim
+1  A: 

Yes, if you're using apache as webserver mod_rewrite might be feasible.
Depending on what you want to achieve it may also be that a simple Alias directive would do the trick.

Alias /forum /path/to/my/program
VolkerK
Hi VolkerK. Thanks. When I was searching for the answer, I also came across this from the Apache site. Didn't understand it though. :(
Jim
VolkerK, I just tried this and nothing. I restarted apache but it will won't work. First, I had put this in the htaccess file and got a 500 server error. I then moved it into the httpd.conf file and tested the configuration with no errors but it will not work. Would you know why?
Jim
Volker, thanks. I got it working with the Alias directive. The reason I couldn't get it to work is because I was missing the quotes.
Jim
I'm currently on a windows machine and will need to change it later when I upload the site and will obviously no longer have to worry about the quotes.
Jim
Do you have a space in one of the directory names? Otherwise you shouldn't need the quotes. You can even use forward-slashes on a windows machine, e.g. `Alias /x d:/xampp/htdocs/public/x`
VolkerK