Jump to content

Recommended Posts

Posted

i'm back, with more problems, and your help is greatly appreciated. here's the problem:

 

i was trying to set up a rss feed for my blog. i know there are probably scripts/programs that generate rss feeds, but since it's just an xml file, i thought i'd write a little script myself. however, on my blog, the url for each file would look something like this:

....../blog/entry.php?id=23&view=simple

so i put the following line in the xml file

<link>....../blog/entry.php?id=23&view=simple</link>

and the browser tells me that it's malformed. it works only if it's something like

<link>....../blog/entry.php?id=23</link>

but i need the 'view=simple' bit in the url, so my first question, then, is is there a way to have 'entry.php?id=23&view=simple' as a link in the xml file? i'm using rss version 2.0 by the way.

 

anyway, i looked a bit on the net and couldn't work out a solution, so i went to plan b. instead of

....../blog/entry.php?id=23&view=simple

i'll change the url to the following

....../blog/entry/23/simple/

and have .htaccess redirect me. this way i can put the link in the rss feed at least. so i went to the .htaccess file in my public_html dir, and added the following lines

RewriteEngine On

RewriteRule entry/(.+)/(.+)(/?)$ entry.php?id=$1&view=$2

however, it didn't work. so i created a directory public_html/blog/entry. then i created a new .htaccess file there, and put the same two lines in that file. it didn't work again. and the error says that 'The requested URL /blog/entry/17/simple/ was not found on this server.'

so what am i doing wrong? is there something wrong with the directive in the .htaccess file, or i should've put it somewhere else?

 

this seems implausible, but maybe servers has to be restarted for the change to take effect? on my linux at home i need to restart the web server if i change something in http.conf, but surely if the .htaccess is already there in the public_html dir there's no need to restart?

 

anyway, solution to just one problem would be sufficient. thanks for your help!

Posted
so i put the following line in the xml file

<link>....../blog/entry.php?id=23&view=simple</link>

and the browser tells me that it's malformed. it works only if it's something like

<link>....../blog/entry.php?id=23</link>

but i need the 'view=simple' bit in the url, so my first question, then, is is there a way to have 'entry.php?id=23&view=simple' as a link in the xml file?

There are certain characters that need to be encoded if they appear within XML data. You have one of those characters in your <link> element data and it's not encoded, which is why your browser complains about your feed being 'malformed'.

 

These are the characters that need to be encoded (replaced with its corresponding HTML entity) in XML data, and what they need to be encoded as:

>& - &
< - <
> - >
' - '
" - "

 

In your case, you have an unencoded '&' in the URL. If you replace the '&' with '&' in your <link> elements:

><link>....../blog/entry.php?id=23&view=simple</link>

...your browser should accept your feed as 'well-formed'.

 

Hope this helps...

Posted

thanks david, that worked right away! i thought the second '=' was the problem because when i tried to open the rss file in my firefox it said that error was with the second '=', so i didn't really look at the '&' at all. it all makes sense now. great!

 

(ok i know i said i only need to get one of the two problems solved, but just out of curiosity, can anyone tell me what's wrong with the .htaccess redirect?)

 

cheers..

Posted

If you're going to put the mod_rewrite lines in the .htaccess file that's in your /public_html directory, you'd need to modify your rule so it's working with the full URL that mod_rewrite is going to see. You probably should also have a RewriteBase directive to tell mod_rewrite what directory its working in:

>RewriteEngine On
RewriteBase /
RewriteRule blog/entry/(.+)/(.+)(/?)$ blog/entry.php?id=$1&view=$2

You don't have to use this, but this rule is a little more specific and perhaps perform a bit better matching:

>RewriteRule blog/entry/([0-9]+)/([^/]+)/?$ blog/entry.php?id=$1&view=$2

You could also put the mod_rewrite directives in an .htaccess file in your /public_html/blog directory, changing the RewriteBase and RewriteRule to reflect the directory they're operating in:

>RewriteEngine On
RewriteBase /blog
RewriteRule entry/(.+)/(.+)(/?)$ entry.php?id=$1&view=$2

You shouldn't need a /public_html/blog/entry directory at all.

 

Hope this helps...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...