Forum Moderators: phranque

Message Too Old, No Replies

using htaccess displays code instead of page

         

lew9e

10:02 pm on Dec 30, 2007 (gmt 0)

10+ Year Member



Hello,

I purchased an article management script that has the option (in the admin - select yes or no) to rewrite the url to seo friendly urls, with the article name in the url instead of the dynamically generated number.

The .htaccess below is the code that comes with the script and is loaded in the scripts main folder along with the script index file.

The script works fine if I delete the htaccess file. With the file, when I enter the url (script folder/index.php), in ie I get a box asking me to save the file, and in ff the page code is automatically displayed. Also, when I tried to use the script installer, I got a message saying 'the requested method POST is not allowed for the url...'.

The company I purchased from says my host does not support htaccess or mod_rewrite, but I am using it for rewriting my stores links, keep my site www, etc (actually you helped me fix it here...thanks again :), so I know they support it.

I hope i'm not missing something...here's the htaccess that came with the script.

AddHandler server-parsed .php
<Files ~ "^[^\.]+$">
SetHandler application/x-httpd-php
</Files>
AddHandler application/x-httpd-php .php

Thanks in advance!

Tony

PHP_Chimp

12:27 pm on Dec 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AddHandler server-parsed .php
<Files ~ "^[^\.]+$">
SetHandler application/x-httpd-php
</Files>
AddHandler application/x-httpd-php .php

This is trying to turn on php. Are you using php for anything else on your site?
As if you are not using php and dont have it installed then when your php pages come through you will be asked to save them...not exactly what you want.

Seeing as the script that you posted isnt rewriting anything...it is just turning on php, im guessing that they have a php script that does the rewriting for you, not using mod_rewrite.

Assuming mod_rewrite is up and running on your site then you should be able to sort out your own rules to convert the links to search engine friendly ones.

lew9e

1:56 pm on Dec 31, 2007 (gmt 0)

10+ Year Member



Hello,

Thanks for explaining that to me. I am using php and I am using rewrites for my store, but I'm no apache expert and the people i purchased this script tell me I have to use this htaccess, which is in the root of their program. I don't really understand, because i have php and mysql, and am using an htaccess to rewrite my store to seo friendly urls, amongst other things...but when I installed this htaccess (above) I get the request to save like you mentioned.

There is an option to turn on url rewrites in the admin panel of the program, but when I do it goes to my error404 page.

I guess I'll see if I can get them to support me on this...as I really have no clue what to do next.

Thanks for your help!

Tony

lew9e

2:36 pm on Dec 31, 2007 (gmt 0)

10+ Year Member



ok so I was thinking (sometimes that can be dangerous)...

If the admin panel has the option to turn on the rewrite, you'd still need to have an .htaccess to carry it out? Is that why it's getting sent to an error 404 page, cause there's no .htaccess (other than the one above which does not rewrite)?

With the option off, the links are written as:

for articles - http://www.example.com/articles/articles.php?art_id=1&start=1

for categories - http://www.example.com/articles/category.php?cat_id=6

when the rewrite option is on:
for articles (article named "default article")- http://www.example.com/articles/article/default-article-1-1.html

for categories (named "furniture and mounts") - http://www.example.com/articles/category/furniture-and-mounts-6-1.html

Do you think an .htaccess rewrite would solve my problem? I'm thinking that must be what's missing.

Sorry if this is basic stuff, but apache rewrites are really new to me and I am trying to learn the syntax for these rewrites.

WEll, thanks again for your time!

Tony

[edited by: encyclo at 3:21 pm (utc) on Dec. 31, 2007]
[edit reason] switched to example.com [/edit]

PHP_Chimp

3:16 pm on Dec 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you already have rewrite rules in another .htaccess file lower down in your directory tree?

As you can have more than 1 htaccess file. So if you have 1 in your root directory rewriting then 1 in another directory also rewriting you need to be careful that you are not rewriting twice. As you are actually getting a different url to what you think you are getting, and this is also not there so you get your 404. It may be worth looking at the server logs to see what url was actually requested, so you can see what is happening.

If you have other htaccess files then have a look at the rules and put [L] at then end of any rules that dont need to be used with another rule. As the [L] stands for last, so once that rule has been applied no others will be. So you get your single rewrite, not 2 or 3 rewrites when you only wanted 1.

jdMorgan

8:55 pm on Dec 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AddHandler server-parsed .php
<Files ~ "^[^\.]+$">
SetHandler application/x-httpd-php
</Files>
AddHandler application/x-httpd-php .php

This code is self-conflicting. Unless the second AddHandler is commented-out, the first one will always be overridden.

Since we do not know the intent of the authors of this code, and how you are supposed to resolve this self-conflicting problem, you'd probably be better off seeking support from them.

If you want to experiment, then try commenting-out that second line, just to see what happens.

I should also note that "application/x-httpd-php" is a MIME-type, not a handler-type, and that it should normally be used with AddType, not AddHandler or SetHandler.

Jim

lew9e

9:25 pm on Dec 31, 2007 (gmt 0)

10+ Year Member



AddHandler application/x-httpd-php .htm
AddHandler application/x-httpd-php .html
#
#<IfModule mod_php4.c>
#php_value session.use_only_cookies 1
#php_value session.use_trans_sid 0
#</IfModule>
#
Options +Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /
#
# Redirect only client-requested dynamic URLs to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /proddetail\.php\?prod=([^&]+)[^\ ]*\ HTTP/
RewriteRule ^proddetail\.php$ http://www.example.com/%1.htm? [R=301,L]
#

I thought of that....here's my current .htaccess (above) on my root (as mentioned, it was kindly cleaned up by the moderator of this forum). I made one change becuase I was getting an error 200, not 404, so i commented out the rewrite to error line and added the standard errordocument code...which didn't work before he helped me with this.

I also removed this htaccess completely and tested my script and it still didn't work.

# Index redirection
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?地spx?夸spx?圭gi如l如hp[2-5]圭fm)[^\ ]*\ HTTP/
RewriteRule ^index\.(html?地spx?夸spx?圭gi如l如hp[2-5]圭fm)$ http://www.example.com/ [R=301,L]
#
# Redirect requests for non-canonical domain
RewriteCond %{HTTP_HOST} ^example\.com(:[0-9]+)?$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
#Rewrite all missing files except .htm to error.php
#RewriteCond %{REQUEST_FILENAME}!-f
#RewriteCond %{REQUEST_FILENAME}!-d
#RewriteRule!\.htm$ /error.php [L]
#
# Rewrite static .htm URLs to dynamic
RewriteRule ^([^.]+)\.htm$ /proddetail.php?prod=$1 [L]

ErrorDocument 404 /error.php

So Currently this is the only htaccess i have on my root, and my new script has no htaccess at all. I might not have been clear on my last posts (lack of sleep happy!, but I DO NOT currently have an htaccess for the rewrite on my article script.

So I'm wondering if that's why it's going to an error 404, because the script is rewriting the code but there's no htaccess to rewrite it?

I tried adding this code to an htaccess in the script folder, but it didn't do anything...probably wrong code?

Here's what I tried to use for my /articles/.htaccess file:

Options +FollowSymLinks
RewriteEngine on

#rewrite from:
#http://www.example.com/articles/category.php?cat_id=6
#rewrite to:
#http://www.example.com/articles/category/furniture-and-mounts-6-1.html

RewriteRule category/cat-id-(.*)\.html$ category.php?cat_id=$1 [R=301,L]

#rewrite from:
#http://www.example.com/articles/articles.php?art_id=2&start=1
#rewrite to:
#http://www.example.com/articles/article/default-article-1-1.html

RewriteRule article/art-id-(.*)-(.*)\.html$ articles.php?art_id=$1&start=$2 [R=301,L]

As mentioned, I'm really a beginner at this, so I'm sure it's not the correct syntax...if you could point me in the right direction i'd appreciate it...or maybe this isn't the problem. I tried to access my ftp logs, but i had a problem so i will have to contact my host.

Well, thanks again for all of your time!

[edited by: jdMorgan at 9:37 pm (utc) on Dec. 31, 2007]
[edit reason] example.com. Please see Terms of Service. [/edit]

jdMorgan

9:42 pm on Dec 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's what I tried to use for my /articles/.htaccess file:

You want an internal rewrite not an external redirect, and the substitution path must be correct. I'd suggest:


Options +FollowSymLinks
RewriteEngine on

RewriteRule ^category/cat-id-([^.]+)\.html$ [b]/articles/[/b]category.php?cat_id=$1 [b][L][/b]

RewriteRule ^article/art-id-([^-]+)-([^.]+)\.html$ [b]/articles/[/b]articles.php?art_id=$1&start=$2 [b][L][/b]


Highlighted code changes for function, other changes for efficiency.

Jim

lew9e

10:37 pm on Dec 31, 2007 (gmt 0)

10+ Year Member



Thanks jdMorgan...none of that worked...i will continue to work with the script company, but it doesn't sound like they know what they're talking about...

anyways, i appreciate your guys' efforts to help me.

Have a Happy New Year!

Tony