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

时间:2014-09-16 22:03:56

标签: wordpress .htaccess

我希望你们可以帮助我。我想重命名我的主题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文件中尝试的内容:

# 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什么都没做。我在这里错过了什么/做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要更改规则的顺序。 wordpress规则将所有请求路由到index.php,包括您的/style.css等网址。所以你需要先将它们路由。

# 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