Jump to content

[SOLVED] Unhelpful Error


mtylerb

Recommended Posts

Hey guys,

 

I have a file that has moved and I'm trying to set up, what should be, a simple PHP header redirect.  In my file at http://www.tbeckett.net/plugins.xhtml I'm using the following code:

 

<?php

header("HTTP/1.0 301 Moved Permanently");
header("Status: 301 Moved Permanently");

header("Location: http://www.tbeckett.net/articles/plugins.xhtml");

?>

 

But I only seem to get an error when I try to open that:

 

XML Parsing Error: no element found

Location: http://www.tbeckett.net/plugins.xhtml

Line Number 8, Column 3

 

:?>

--^

 

Can anyone help me with this?  I have the exact same script running in a number of other files, since I changed the structure of my page, they all work fine, it's just this one.

Link to comment
Share on other sites

Look up source of this file in browser, to see what's causing it.

 

My bet is... your php code did not run, because the file has xhtml extension. You should use mod_rewrite, to rewrite plugins.xhtml.php into plugins.xhtml

 

[edit]

 

Or as premiso says, configure your server, to parse .xhtml files as php... I'm not sure if it's good idea though.

 

 

Link to comment
Share on other sites

Is there a way to fix this?  The other files are all xhtml as well, for example,

 

http://www.tbeckett.net/articles/libertarianism.xhtml

 

Redirects to

 

http://www.tbeckett.net/articles/politics/libertarianism.xhtml

 

With no trouble.

 

EDIT:  Ok, you've offered ways to fix it, sorry, missed that.  How would I do that with mod_rewrite?  I already use mod_rewrite to remove the question mark from the url.  I didn't design it though and the original 301 redirects that were put in the .htaccess never worked.

Link to comment
Share on other sites

Look up source of this file in browser, to see what's causing it.

 

My bet is... your php code did not run, because the file has xhtml extension. You should use mod_rewrite, to rewrite plugins.xhtml.php into plugins.xhtml

 

[edit]

 

Or as premiso says, configure your server, to parse .xhtml files as php... I'm not sure if it's good idea though.

 

 

 

Sorry I was not hinting that he should change his server to parse .xhtml as php. Should have been clearer on it.

 

mod_rewrite would be better, that way you would not have to create a file plugins.xhtml, or you could even have the .htaccess do the redirect for you.

 

http://www.isitebuild.com/301-redirect.htm

 

Will help with the .htaccess 301 redirect.

Link to comment
Share on other sites

Ok, thank you, I figured out the .htaccess thing.  Just placed the following code in and it worked perfectly:

 

redirect 301 /plugins.xhtml http://www.tbeckett.net/articles/plugins.xhtml

 

I don't know why it didn't work before.  Thanks for your help Mchl and premiso!

 

EDIT:  Actually, I just noticed that it's now sending me to:  http://www.tbeckett.net/articles/plugins.xhtml?plugins.xhtml

 

My .htaccess looks like:

 

Options +FollowSymLinks
AddDefaultCharset UTF-8
redirect 301 /plugins.xhtml http://www.tbeckett.net/articles/plugins.xhtml

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  # Administration URL rewriting.
  RewriteRule ^admin(.*)$ admin/index.php?$1 [L,QSA]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  # Main URL rewriting.
  RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>

 

Any ideas?

Link to comment
Share on other sites

Ok, after playing around, I got it.  Changed my .htaccess to:

 

Options +FollowSymLinks
AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  
  RewriteRule ^plugins.xhtml articles/plugins.xhtml [R=permanent,L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  # Administration URL rewriting.
  RewriteRule ^admin(.*)$ admin/index.php?$1 [L,QSA]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  # Main URL rewriting.
  RewriteRule ^(.*)$ index.php?$1 [L,QSA]


</IfModule>

 

Adding that first RewriteRule in.  While you're reading this, could someone tell me what the !-l, !-f, and !-d mean?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.