开发者

mod_rewrite and relative HTML links

开发者 https://www.devze.com 2023-04-05 15:29 出处:网络
I wrote a simple mod_rewrite to convert my ugly URLs: <IfModule mod_rewrite.c> RewriteEngine on RewriteRule news\\/([^\\/]+)/([0-9]+)-([^\\/]+)$news.php?id=$2

I wrote a simple mod_rewrite to convert my ugly URLs:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule news\/([^\/]+)/([0-9]+)-([^\/]+)$     news.php?id=$2
  RewriteRule (.*)/images/(.*)$                     images/$2
  RewriteRule (.*)/css/(.*)$                            css/$2
  RewriteRule (.*)/js/(.*)$                         js/$2
</IfModule>

A problem immediately arose because all images, scripts, and styles are requested relative to the fake URL. So I had to append the next 3 end-of-line assertion for the regex and add the next 3 rules. What I am asking is that whether this approach is good or is it consuming too much resources? I know that this can be solved via absolute links but my laziness prompted me to try this solution which has a site-wide effect. Or is there a better solution?

One thing that was suggested was prepending slashes to the links. The problem is that the site can be accessed via two domains: foo.com and bar.com/baz/qu开发者_StackOverflowx/ so I really can't use that.

Any help would be appreciated. Thanks!


You could also add a <base href=""/> to your html files, which saves you the images/css/js rewrite rules.

About "consuming too much resources" - when you get really really many accesses, it will fall on your feet for sure. But I doubt that you'll come into that traffic region.

0

精彩评论

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