开发者

.htaccess rewrite rule causing javascript error?

I have a strange problem, where if I write a rule to match a开发者_运维技巧ny 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.


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]


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜