I have a script that uses mod_rewrite to alter all the urls. However, the script is based in a sub-directory, rather than root, and all the urls are being rewritten to root, which makes them incorrect. The onlt thing I can think of that could be doing this for all files is the .htaccess file (below). Is this the case and how would I alter it if so? RewriteEngine On #turn on the Rewrite engine, if it's not already active #set the base directory to / RewriteBase / # now the rewriting rules RewriteRule ^games/ games.php [L] # now the rewriting rules RewriteRule ^game/ game.php [L] Code (markup):
Change #set the base directory to / RewriteBase / Code (markup): to #set the base directory to /subdir/ RewriteBase /subdir/ Code (markup): (where subdir is the name of your subdirectory, obviously)
Hmm, I tried that and it didn't work. Could the fact that it's on a subdomain too be causing a problem?
That didn't fix it either. I can't see what else would affect all the files in the directory, except the .htaccess file.
I'm not sure because you have not post your origin and destiny urls, but maybe you need something like this: RewriteRule ^gam(e|es)\/(.+)\.html /games.php?$2
Hmm, out of curiosity, but why do you have an ending slash if the rewriterule automatically does the slash for you?
All the files are supposed to end up in games.directorygold.com/GameZone however, they're being written into games.directorygold.com which means all links are broken. I can fix it be editing every file that has a url in it, but I thought it would be something global. I have no idea regarding the trailing slash, that's how it came with the script and I know almost nothing abut .htaccess. Going to give the other ideas a try.
Do you have the correct href location for your links (i.e. the status bar shows games.directorygold.com/GameZone when you hover over the link)? If not, it's not actually a problem with mod_rewrite - it'd be a problem with your script. The best solution would be to update the script but you could also use mod_rewrite to transparently add in that missing directory. Jim's suggestion should do this for you. If the links are correct, then the problem is to do with your rewrites. Altering the rewrite base should work, or add in the extra subdirectory to both the pattern and destination. mod_rewrite can only intercept requests and rewrite to a different location. It can't alter the output of your scripts to make URLs in the proper format.