我发现了很多关于创建漂亮的URI和不使用mod_rewrite的东西,但是我正在寻找的是一种移除URL元素的方法(就浏览者而言),而不仅仅是移动物体和/或重新组织。用mod_rewrite改变站点的URL
我需要这样的:
是这样的:
基本上,让我们摆脱在URL /富的。
这可能吗?
我发现了很多关于创建漂亮的URI和不使用mod_rewrite的东西,但是我正在寻找的是一种移除URL元素的方法(就浏览者而言),而不仅仅是移动物体和/或重新组织。用mod_rewrite改变站点的URL
我需要这样的:
是这样的:
基本上,让我们摆脱在URL /富的。
这可能吗?
您可以轻松地做到这一点,只需丢弃你不想失去什么:
RewriteEngine On
RewriteRule ^foo/(.*)$ $1 [R=301,NE,L]
这应该有效地从你的URL中移除foo/
。如果您不希望地址栏反映此更改,请删除R=301
。参数NE
用于确保请求未被转义。
这难道不是和他想要的完全相反吗?他希望URL为example.com/bar,并在/ foo/bar中引用该文件。这个重写规则似乎将example.com/foo/bar变成了/ bar中的文件。或者,也许我只是不够了解mod_rewrite? – 2009-07-27 23:49:44
注意:大多数这些说明来自here, "Giving Wordpress its Own Directory"。
如果是WordPress的明确,这可以通过添加像这样到你想成为基本目录中的index.php文件处理:
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./blog2/wp-blog-header.php');
?>
在WordPress的设置,你需要让它知道了 “实际的” WordPress的URL,并且希望其他人使用之间的差异:
(这些都是在“设置”我...)
另外,我不记得,如果这是自动还是没有这样做(我认为这是),但如果你把对的.htaccess index.php文件将需要如下所示:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
这是什么逻辑?这仅仅是一个控制器? – 2009-07-27 23:38:39
只是为了清理网址,真的。这是一个WordPress的安装,它坐在public_html的dir目录下。只是想清理干净。 – 2009-07-27 23:53:33