May 16, 200719 yr I'm making a website where the host is running PHP as CGI which is new to me. I just uploaded the first test and ran into some problems. I've set up www.example.com/feed/news.xml to point to www.example.com/feed.php?feed=news On my local system that runs PHP on apache it works fine. However, on the live server I get a "No input file specified" message when trying to access www.example.com/feed/news.xml If I create a folder names 'feed' it works! Why is this? This is not a problem for the feed. But I also have set up a news system where the URL's looks like this: www.example.com/news/2007/05/title-text/ which points to www.example.com/news.php?year=2007&month=05&title=title-text Because it's all dynamic I can't get away with just fudging it by creating dummy folders. Any idea of why this is happening?
May 16, 200719 yr Hi Thomas, Hmmmmm, sounds like it could possibley be that your host hasn't enabled Mod_Rewrite ? You can do a check by doing the following: Create a .htaccess file with the following: Options +FollowSymLinks RewriteEngine On Save the file to a subdirectory of your main site something like this /modtest/.htaccess Now attempt to browse to the subdirectory (http://localhost/modtest/). One of two things could happen - No errors, Congrats mod_rewrite engine is now enabled. - 500, Internal Server Error If you get this message then mod_rewrite was not installed/enabled on your host. You may want to ask your host if they can enable it. Hope that helps.
May 16, 200719 yr Author mod_rewrite is enabled. other rewrite rules which rewrites .html files to .php files works. I just added "cgi.fix_pathinfo = 1" to php.ini and that put an end to the "No Input" error messages. But I still get an 404 trying to access the feed unless I have a 'feed' folder in the root. Hi Thomas, Hmmmmm, sounds like it could possibley be that your host hasn't enabled Mod_Rewrite ? You can do a check by doing the following: Create a .htaccess file with the following: Options +FollowSymLinks RewriteEngine On Save the file to a subdirectory of your main site something like this /modtest/.htaccess Now attempt to browse to the subdirectory (http://localhost/modtest/). One of two things could happen - No errors, Congrats mod_rewrite engine is now enabled. - 500, Internal Server Error If you get this message then mod_rewrite was not installed/enabled on your host. You may want to ask your host if they can enable it. Hope that helps.
May 16, 200719 yr Author I just found out that the site by default, without any .htaccess files, redirects URLs like www.example.com/test/ into www.example.com/test.php So when I request www.example.com/news/2007/05/title-text/ it points to www.example.com/news.php but NONE of the arguments are being passed on. the $_GET superglobal is empty. what gives?
May 16, 200719 yr I just found out that the site by default, without any .htaccess files, redirects URLs like www.example.com/test/ into www.example.com/test.php So when I request www.example.com/news/2007/05/title-text/ it points to www.example.com/news.php but NONE of the arguments are being passed on. the $_GET superglobal is empty. what gives? the super globals cant pass, as the URL needs to be bengribbin.com/news.php?ben=cool&&me=helpful If the URL is rewritten, I am not sure it can GET the info from the URL
May 16, 200719 yr mod rewrite doesn't affect the $_GET variables, you can still use them in the way you want as long as your mod rewrite rules are correctly written. Wildo
May 16, 200719 yr then you should contact your host with the problems you are getting, if you're host is a bit decent they will help you out for sure. Wildo
May 16, 200719 yr Author Yea, seem like that's what I'll have to do. Problem is that it's a community site and I don't have control over it myself. I'm just the code monkey. Otherwise I'd get a different host which'd fit better.
May 16, 200719 yr Have you got the rewrite base set up in your htaccess? RewriteBase /domains/yoursite/html This is only an example but you need to tell the engine wher to rewrite from... Oli
May 16, 200719 yr Author I set RewriteBase to / thinking it'd be the root of my domain. Is that not the case? the thing is, rewrites for .html files to .php files work. ...hm... maybe that is because they get inherited.... ok, this my .htaccess file: Options +FollowSymlinks #Options -Indexes #IndexIgnore *.php *.inc RewriteEngine on RewriteBase / #Directory Index index.php # Deny access to the .htaccess file <Files .htaccess> order allow,deny deny from all </Files> # Hide the php directory and php files RedirectMatch 404 /\php(/|$) #RedirectMatch 404 ^(.*)\.php$ #Alias / /php #AliasMatch ^/icons(.*) /usr/local/apache/icons$1 #AliasMatch ^/(.*\.php) /server_root/php/$1 #AliasMatch ^/(.*\.php) /php/$1 # Redirect desktopx.info to www.desktopx.info RewriteCond %{HTTP_HOST} (^desktopx\.info$) [NC] RewriteRule ^(.*)$ http://www\.desktopx\.info/$1 [L,R=301] # Redirect index files to / RedirectMatch 301 ^(.*)index\.htm$ $1 RedirectMatch 301 ^(.*)index\.html$ $1 # Redirect htm files to html RedirectMatch 301 ^(.*)\.htm$ $1.html # Root rewrite RewriteRule ^default\.html$ /index.php RewriteRule ^register\.html$ /register.php RewriteRule ^activate\.html$ /activate.php # RSS rewrite RewriteRule ^feed/news\.xml$ /feed.php?feed=news # Admin tools rewrite RewriteRule ^admin/default\.html$ /admin/index.php RewriteRule ^admin/site\.html$ /admin/site.php RewriteRule ^admin/news\.html$ /admin/news.php RewriteRule ^admin/tutorials\.html$ /admin/tutorials.php RewriteRule ^admin/snippets\.html$ /admin/snippets.php RewriteRule ^admin/setup_db\.html$ /admin/setup_db.php # News rewrite RewriteRule ^news/$ /news.php RewriteRule ^news/(\d\d\d\d)/$ /news.php?year=$1 RewriteRule ^news/(\d\d\d\d)/(\d\d)/$ /news.php?year=$1&month=$2 RewriteRule ^news/(\d\d\d\d)/(\d\d)/([a-zA-Z0-9_\-]+)/$ /news.php?year=$1&month=$2&title=$3 # Todo RewriteRule ^users/ /todo.php RewriteRule ^tutorials/ /todo.php RewriteRule ^snippets/ /todo.php RewriteRule ^projects/ /todo.php RewriteRule ^forum/ /todo.php The test site is: http://testsite.desktopx.info/ (and I don't get why it keep redirecting http://testsite.desktopx.info/ to http://testsite.desktopx.info/default.html ... grrr)
May 17, 200719 yr Author I think I'm getting closer. Seem to be something called Content Negotiation. http://www.the-art-of-web.com/system/rewrite/1/ Gotto find a way to disable it.
May 17, 200719 yr Author Got it working somewhat. But there are things I don't understand: For some reason this worked on my local test server, but not on the host: # News rewrite RewriteRule ^news/$ /news.php RewriteRule ^news/(\d\d\d\d)/$ /news.php?year=$1 RewriteRule ^news/(\d\d\d\d)/(\d\d)/$ /news.php?year=$1&month=$2 RewriteRule ^news/(\d\d\d\d)/(\d\d)/([a-zA-Z0-9_\-]+)/$ /news.php?year=$1&month=$2&title=$3 I had to use this on the live server: RewriteRule ^news/$ news2.php RewriteRule ^news/([0-9]{4})/$ news2.php?year=$1 RewriteRule ^news/([0-9]{4})/([0-9]{2})/$ news2.php?year=$1&month=$2 RewriteRule ^news/([0-9]{4})/([0-9]{2})/([a-zA-Z0-9_\-]+)/$ news2.php?year=$1&month=$2&title=$3 The news2.php bit was so I could work around the Content Negotiation. And that's another thing. I tried placing the news.php file in a folder named 'php' so the rules would look like this: RewriteRule ^news/$ php/news.php RewriteRule ^news/([0-9]{4})/$ php/news.php?year=$1 RewriteRule ^news/([0-9]{4})/([0-9]{2})/$ php/news.php?year=$1&month=$2 RewriteRule ^news/([0-9]{4})/([0-9]{2})/([a-zA-Z0-9_\-]+)/$ php/news.php?year=$1&month=$2&title=$3 But that resulted in a 404. The PHP folder permissions are 755. At the top of the .htaccess I set RewriteBase /
Create an account or sign in to comment