0

I have a strange problem, where if I write a rule to match any character (.*), firebug throws up a javascript syntax error.

The rule I have is:

RewriteRule ^news/story/(.*)? index.php?page=viewNews&story=$1 [L,NC]

The error that appears is:

syntax error
[Break On This Error] <!DOCTYPE html PUBLIC "-//W3C//DTD XHT.../xhtml1/DTD/xhtml1-transitional.dtd"> 

If I change the rule to be:

RewriteRule ^news/story/(\d+)? index.php?page=viewNews&story=$1 [L,NC]

It works fine, but only for numbers obviously. I want it to work for text as well, hence the wildcard.

If I go to the index.php?page=viewNews&story=test+story page directly, it works fine.

2
  • Look in the firebug if html page returned for one of the linked script files on the page. Commented Jan 31, 2011 at 17:09
  • Firebug refers to a linked script, yes. Taking that script out then brings the same error up for the next linked script, and so on. If I take all javascript files out, it works. But, I do not believe the javascript is at fault here, as there are no errors if I go direct to the url as I described above. Commented Jan 31, 2011 at 18:39

2 Answers 2

4

I suspect that your javascripts are also contained in the path /news/story/* and that these requests are being rewritten.

You can fix this by setting a rewrite condition that will only rewrite if a file (or directory) doesn't exist:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^news/story/(.*)? index.php?page=viewNews&story=$1 [L,NC]
Sign up to request clarification or add additional context in comments.

3 Comments

The javascript files are stored in /scripts. I gave your conditions a go, but still the same thing unfortunately.
Got it fixed. You weren't far off! The rule was correct, but my header file had a relative link to the scripts folder, which of course was being affected by the rewrite rule.
you probably still want to keep the rewrite conditions as above, though - unless you want to rewrite away from physical files.
0

Another posibility would be

RewriteCond %{QUERY_STRING} !rewrite=no [NC]

add this to your Conditions

and add a parameter to the files you dont want to have redirected

<script type="text/javascript" src="ajax.js?rewrite=no"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.