View Full Version : php url redirection

20th July 2011, 12:34 AM
I am not sure though if the requirement I have is called "redirection". This is what the problem is all about.

If I type in www.mysite/index.php/searchitem (http://www.mysite/index.php/searchitem), the page index.php will be executed with:



But if I request www.mysite/searchitem (http://www.mysite/searchitem), index.php will be executed with



I then simply match 'REQUEST_URI' and 'SCRIPT_NAME' to figure out what is being requested.

This url format works under apache by adding in .htaccess:
RewriteRule . index.php

I could not make the second example (the one without index.php) work under IIS. It keeps on telling me that the path/page I requested does not exists.

In fact $_SERVER['REQUEST_URI'] is not provided under IIS. I had to check if $SERVER['REQUEST_URI'] is set. and if not, then I set in manually.

Thanks in advance for any advice.

20th July 2011, 01:06 AM
Try adding a '/' :

RewriteRule . /index.php

ETA: You'll probably want to add QSA as a flag to that

20th July 2011, 02:37 AM

It works now. The only thing is for apache, the file .htaccess is used while in IIS, the file is web.config.

Just in case others are interested,

(Apache) .htaccess:

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

for IIS - web.config

<?xml version="1.0" encoding="UTF-8"?>
<identity impersonate="false" />
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<add input="{URL}" pattern="^/webitor/api.*$" ignoreCase="false" />
<action type="Rewrite" url="webitor/webitor_api.php" appendQueryString="true" />
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{URL}" pattern="^/webitor/api.*$" ignoreCase="false" negate="true" />
<action type="Rewrite" url="index.php" appendQueryString="true" />
<directoryBrowse enabled="false" />

ETA: don't know why some words are suppressed by rule 2.