.htaccess的“漂亮网址”中断图像src [英] .htaccess "pretty urls" breaks images src

查看:166
本文介绍了.htaccess的“漂亮网址”中断图像src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.htaccess代码使用以下代码将blog.php转换为/ blog /:

I am using .htaccess code to turn blog.php into /blog/ with this code:

# --- CUTENEWS[ST]
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^blog(\d+)*$ ./blog.php
RewriteRule ^blog/(\d+)*$ ./blog.php

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /blogengine/show_news.php?cn_rewrite_url=$1 [L]

# --- CUTENEWS[ED]

这很好用,除非当我用/ blog /加载网页时,图像会中断。如果我使用/blog.php或/ blog加载网页,则图像加载正常。

This works fine, except when I load the web page with /blog/, the images break. If I load the web page with /blog.php or /blog, the images load fine.

我一直在搜索人们在Stackoverflow上遇到的所有.htaccess问题,而这是使我工作正常的范围。之所以有cutenews php,是因为我在我的网站中使用了cutenews进行博客集成。

I have been searching through all the .htaccess issues people have had on Stackoverflow, and this is as far as I have come to getting things working. The cutenews php is there because I am using cutenews for blog integration in my site.

我非常感谢任何建议。我对.htaccess

I appreciate any suggestions. I am pretty new to .htaccess

推荐答案

不太熟悉。此 RewriteRule ^ blog(\d +) $ *与 / blog / 不匹配。请尝试以下操作:

You are not accounting for trailing slash. This RewriteRule ^blog(\d+)$* will not match /blog/ .Try this instead:

RewriteRule ^blog/([0-9]+[^/])*$ /blog.php/$1

编辑:
正如我们在聊天中讨论的那样,您还需要其他东西,这里是:

As we discussed in chat you needed something else, here it is:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^blog(.*)$ /blog.php?route=$1 [R=301,L]

这将捕获以下URL:/ blog,/ blog /,/ blog / anythig_goes_here / 2343 /。添加301永久重定向标头,L表示不处理其他规则。

This will catch URLS like: /blog, /blog/, /blog/anythig_goes_here/2343/ . Adding 301 Permanent Redirect header, and L meaning don't process other rules.

在您的blog.php中,您可以通过以下方式到达路由参数:

in your blog.php you can reach 'route' paremeter via:

echo $_GET['route'];

编辑:

进一步讨论之后,通过从重定向url开头删除 /解决了该问题,因此现在重写规则行如下所示:

After discussing further, the issue was solved by removing "/" from the begining of the redirect url, so now that rewrite rule line looks like:

RewriteRule ^blog(.*)$ blogposts.php?route=$1 [L]

对于图像,需要使用绝对URL,以 /开头指向您的Web根。

For images, absolute urls need to be used, starting with "/" pointing to your web root.

这篇关于.htaccess的“漂亮网址”中断图像src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆