首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用.htaccess重写主题路径?

如何使用.htaccess重写主题路径?
EN

Stack Overflow用户
提问于 2014-09-16 22:03:56
回答 1查看 900关注 0票数 2

我希望你们能帮我一把。我想重命名我的主题的CSS & JS路径,但我似乎无法弄清楚。例如:

我想要改变:

http://cdn.(domain-name).com/wp-content/themes/smart-mag/style.css

http://cdn.(domain-name).com/style.css

&来自:

http://cdn.(domain-name).com/wp-content/themes/smart-mag/js/bunyad-theme.js

http://cdn.(domain-name).com/js/bunyad-theme.js

等等

下面是我在我的.htaccess文件中尝试的内容:

代码语言:javascript
复制
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^wp-content/themes/smart-mag/screenshot\.png|readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$ /nothing_404_404 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
RewriteCond %{REQUEST_URI} \.(css|js|jpe?g|gif|png|bmp)$
RewriteCond %{REQUEST_URI} !^/themes/smart-mag/
RewriteRule ^(.*) /themes/smart-mag/$1 [L]
</IfModule>
#END WordPress 

修改后的htaccess根本没有任何作用。我在这里错过了什么/做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2014-09-16 23:16:16

你需要改变你的规则的顺序。wordpress规则将所有请求路由到index.php,包括您的/style.css等URL。所以你得先给他们安排路线。

代码语言:javascript
复制
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} \.(css|js|jpe?g|gif|png|bmp)$
RewriteCond %{REQUEST_URI} !^/themes/smart-mag/
RewriteRule ^(.*) /themes/smart-mag/$1 [L]

RewriteRule ^index\.php$ - [L]
RewriteRule ^wp-content/themes/smart-mag/screenshot\.png|readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$ /nothing_404_404 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
#END WordPress 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25879153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档