Web Hosting Talk







View Full Version : another mod rewrite q


section31
04-27-2004, 11:29 PM
http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html
http://www.engelschall.com/pw/apache/rewriteguide/
After reading through these...I still can't get this darn simple mod rewrite rule to work. Can anyone help.
Trying to have this... ex. www.mydomain.com/123 redirect to www.mydomain.com/in.php?link=123

This is what I have, Am I even close?
RewriteEngine on
RewriteRule ^/(.*) /in.php?link=$1 [R]

Thanks for your time,
Dave

k2host
04-28-2004, 12:12 AM
Try this in your .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteRule /(.*) /in\.php?link=$1

section31
04-28-2004, 12:14 AM
nope...sorry...I got a 404 error.

k2host
04-28-2004, 12:15 AM
section31:

Just to make sure, I had updated my post a few times, so look at it again and see that you're using the exact same code as is currently up there..

section31
04-28-2004, 12:17 AM
ok..i added that escape character before the period...still nothing...hm... any other suggestions

k2host
04-28-2004, 12:19 AM
what's your url? does the in.php file exist?

section31
04-28-2004, 12:20 AM
yah...look..

www.imgod.us/in.php?link=1

www.imgod.us/1

k2host
04-28-2004, 12:23 AM
Okay, can you look in your web server error logs and see exactly which file "was not found"? That will give you a good clue as to what's going wrong.

section31
04-28-2004, 12:25 AM
ok..just checked...no redirection is being made..just saying /home/myuser/public_html/1 doesn't exist...

k2host
04-28-2004, 12:26 AM
Okay, apache may not be configured to allow for .htaccess files..

Try putting the code in the apache config file under the virtual host block for you domain, just copy and paste and restart apache.

section31
04-28-2004, 12:29 AM
hm...i c..well i wish i had root access..but i don't...this is a shared server i'm on...So, I guess its time to ask my host.....Thanks for all the help k2host...

1 question...so whats with the escaping the period...do i need that. and would the code I had before work.

k2host
04-28-2004, 12:30 AM
no problem, good luck with it... if your host doesn't help you out let me know and I can put you on one of my servers for whatever price you're currently paying.

digitok
04-28-2004, 03:51 AM
Try RewriteRule ^([0-9]+) /in.php?link=$1

section31
04-28-2004, 04:28 AM
Originally posted by digitok
Try RewriteRule ^([0-9]+) /in.php?link=$1

I can't believe it...it works...

I'm familiar with reg exp and I don't see why a .* would mess it up.

digitok
04-28-2004, 08:58 AM
Well I changed it to [0-9] so it only matches the numbers and not if you did blah.com/dir/etc/...

The problem lied in the / at the beginning of your Rewrite Rule, the rewrite starts after the . (blah.com/test) = test, not /test

But in the redirect section you do need to use / (well depending on the type of path you want).

section31
04-28-2004, 01:01 PM
well...thats the thing...the problem isn't only on the slash.... I'm trying various regular expressions and I get a 500 error.

I tried these and none work...only the [0-9]
(.+)
(.*)
([A-Za-z0-9])
([a-z0-9])

section31
04-28-2004, 06:11 PM
interesting...
I hadn't tried just using [A-Z] rather than [a-z]...
You would never guess what happened.

I get this error on my apache log file.
RewriteRule: cannot compile regular expression '^([a-z]+)'

Yet it goes perfectly through ^([A-Z]+)

why the hell is it having problems with a lowercase list. Any ideas...