【问题标题】:htaccess url rewrite affecting internal urls? [duplicate]htaccess url重写影响内部url? [复制]
【发布时间】:2017-06-30 06:39:26
【问题描述】:

我的网址如下所示:

website.com/proj1/post.php?id=130

我想改写成:

 website.com/proj1/post/130

以下 htaccess 规则为我重写了 url:

RewriteEngine on
RewriteRule ^post/([^/.]+)/?$ /proj1/post.php?id=$1 [L]

但问题是规则也会影响内部网址。

例如重写

<img src="/images/ex.jpg" />

<img src="post/images/ex.jpg" />

有没有办法排除内部链接?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    如果文件或文件夹实际存在,添加以下行将忽略重写规则

       RewriteCond %{REQUEST_FILENAME} -f [NC,OR] 
       RewriteCond %{REQUEST_FILENAME} -d [NC] 
       RewriteRule .* - [L]
    

    【讨论】:

    • 这不是这里的问题。请参阅链接的帖子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多