Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Wordpress 3.6.1中使用图像的动态路径_Wordpress_.htaccess - Fatal编程技术网

如何在Wordpress 3.6.1中使用图像的动态路径

如何在Wordpress 3.6.1中使用图像的动态路径,wordpress,.htaccess,Wordpress,.htaccess,目前我正在Wordpress网站上工作 我的Web服务器上有多个网站,因此我的Wordpress网站位于http://localhost/wordpress/ 现在我想为我的图像创建动态路径 作为我的标志我使用的HTML <img src="images/logo.png" /> 这只是在我的主页上工作。当我进入联系人页面时http://localhost/wordpress/contact 我需要将我的徽标HTML更改为,以便在页面上工作 如何将htaccess记录指向根目录,以

目前我正在Wordpress网站上工作

我的Web服务器上有多个网站,因此我的Wordpress网站位于
http://localhost/wordpress/

现在我想为我的图像创建动态路径

作为我的标志我使用的HTML

<img src="images/logo.png" />
这只是在我的主页上工作。当我进入联系人页面时
http://localhost/wordpress/contact

我需要将我的徽标HTML更改为
,以便在页面上工作

如何将htaccess记录指向根目录,以便我始终可以使用路径
images/(.*)

我想我忘记了重写cond,但我尝试了一些,但没有效果,甚至出现了一些内部服务器错误

我该怎么做

我的完整
.htaccess
看起来像

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]

    RewriteRule ^images/(.*)$ wp-content/uploads/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写BASE/wordpress/
重写规则^index\.php$-[L]
重写规则^images/(.*)$wp content/uploads/$1[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/wordpress/index.php[L]
#结束WordPress

请确保对始终以
/
开头的图像使用绝对URL

 <img src="/images/logo.png" />

不幸的是,这在我的主页和联系人页面上都不起作用。是的,现在它起作用了。但是,当我将Wordpress网站移动到根域或移动到托管服务时,我需要更改所有图像源。这样,我的链接就不再是动态的了。我想要的只是在我的图像路径中使用
/images/
部分。更改
.htaccess
中的1行即可。但现在我无法移动我的网站。因此,您担心将来会将WP安装路径更改为
/wordpress
以外的其他路径吗?请检查编辑后的答案。现在,该规则应该放在
文档的\u ROOT/.htaccess
中。这样,您就不需要在所有图像中添加
/wordpress
 <img src="/images/logo.png" />
RewriteRule ^images/(.+)$ /wordpress/wp-content/uploads/$1 [L,NC]