views:

270

answers:

2

Hello!

I'm working on a url shortner script. It's located at http://mini.ample.se/ and the short URL will look something like http://mini.ample.se/%5Babc..%5D

my .httaccess file looks like this

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteOptions MaxRedirects=1
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule ^([a-zA-Z0-9_-]+)$ redirect.php?alias=$1 [L]
</IfModule>

when I try it out with ex. mini.ample.se/a I get "No input file specified" error. I know it got something to do with the redirecting and not finding my redirect.php file but I'm not sure what.

redirect.php file looks like this

$alias = trim(mysql_real_escape_string($_GET['alias']));

if (!preg_match("/^[a-zA-Z0-9_-]+$/", $alias)) {
  header("Location: ".SITE_URL, true, 301);
  exit();
}

if (($url = get_url($alias))) {
    header("Location: $url", true, 301);
    exit();
}

header("Location: ".SITE_URL, true, 301);

Thanks!

A: 

I'm pretty sure this is a 'file not found' issue, that the php file is not found and its kicking back an error, I think your rewrite needs to have a condition that will not 'rewite' a certain request:

RewriteCond $1 !^(redirect\.php)

$1 being the value of course that is being passed.. just an example but I believe this is whats happening. Give it a try.

EDIT: Did a search, looks like this could help you: http://jenseng.com/archives/000035.html

Jakub
A: 

mod_rewrite can log a lot of debug information. Just increase the log level and set a log file

RewriteLogLevel 9
RewriteLog logs/rewrite.log

prints e.g. something like

(3) [perdir D:/xampp/htdocs/so/rewrite/] strip per-dir prefix: D:/xampp/htdocs/so/rewrite/yadda -> yadda
(3) [perdir D:/xampp/htdocs/so/rewrite/] applying pattern '^([a-zA-Z0-9_-]+)$' to uri 'yadda'
(4) [perdir D:/xampp/htdocs/so/rewrite/] RewriteCond: input='D:/xampp/htdocs/so/rewrite/yadda' pattern='!-f' => matched
(4) [perdir D:/xampp/htdocs/so/rewrite/] RewriteCond: input='D:/xampp/htdocs/so/rewrite/yadda' pattern='!-d' => matched
(4) [perdir D:/xampp/htdocs/so/rewrite/] RewriteCond: input='D:/xampp/htdocs/so/rewrite/yadda' pattern='!-l' => matched
(2) [perdir D:/xampp/htdocs/so/rewrite/] rewrite 'yadda' -> 'redirect.php?alias=yadda'
(3) split uri=redirect.php?alias=yadda -> uri=redirect.php, args=alias=yadda
(3) [perdir D:/xampp/htdocs/so/rewrite/] add per-dir prefix: redirect.php -> D:/xampp/htdocs/so/rewrite/redirect.php
(2) [perdir D:/xampp/htdocs/so/rewrite/] trying to replace prefix D:/xampp/htdocs/so/rewrite/ with /
(5) strip matching prefix: D:/xampp/htdocs/so/rewrite/redirect.php -> redirect.php
(4) add subst prefix: redirect.php -> /redirect.php
(1) [perdir D:/xampp/htdocs/so/rewrite/] internal redirect with /redirect.php [INTERNAL REDIRECT]

Esp. take a look at the (1) ... internal redirect line in your log. That's (not quite but) almost like a new request to your server, i.e. /redirect really means http://your-server/redirect.php

VolkerK