Wordpress永久链接隐藏目录名称

时间:2010-09-16 16:17:09

标签: wordpress url-rewriting

我的Wordpress安装位于名为/ wordpress的目录中。

我已将自定义永久链接激活为/%category%/%postname%/

为了隐藏目录名“wordpress”,重写代码是什么。

我需要myblog.com/category/post而不是myblog.com/wordpress/category/post

... THX

1 个答案:

答案 0 :(得分:0)

看看:http://www.webmasterworld.com/apache/3389121.htm

这是你要问的一个问题的确切问题。 POST的示例。放入.httaccess文件。

让我们说用户看到的文件名前面有aaa-或bbb-等,实际的文件夹名是/ 111 /和/ 222 /等。

这些名称可以是您想要的名称,您可以决定它们是什么,并在修改代码时在某处创建一个列表:

# == REDIRECTS to PROTECT FOLDER nameS FROM BEING INDEXED ==

# Redirect a direct request for any /nnn folder URL back to root to avoid Duplicate Content (also fixes domain as www).

rewriteCond %{REQUEST_URI} ^111 [NC]
rewriteRule ^111/(.*)$ http://www.main-site.com/aaa-$1 [R=301,L]

rewriteCond %{REQUEST_URI} ^222 [NC]
rewriteRule ^222/(.*)$ http://www.main-site.com/bbb-$1 [R=301,L]

rewriteCond %{REQUEST_URI} ^333 [NC]
rewriteRule ^333/(.*)$ http://www.main-site.com/ccc-$1 [R=301,L]

# == REDIRECT ALL NON-WWW REQUESTS to WWW ==

# Redirect any non-www request to www to avoid Duplicate Content problems.

rewriteCond %{HTTP_HOST} ^main-site\.com [NC]
rewriteRule ^(.*)$ http://www.main-site.com/$1 [R=301,L]

# == rewrite BASE URLS to FOLDERS ==

# Silently rewrite a request that is not for a /nnn URL to the nnn folder (www has already been fixed by previous rule).

rewriteCond %{REQUEST_URI}!(.*)111
rewriteRule ^aaa-(.*)$ /111/$1 [L]

rewriteCond %{REQUEST_URI}!(.*)222
rewriteRule ^bbb-(.*)$ /222/$1 [L]

rewriteCond %{REQUEST_URI}!(.*)333
rewriteRule ^ccc-(.*)$ /333/$1 [L]