2012-01-16 54 views
2

删除子目录形式的URL我有一个URL结构,这样htaccess的:同时担任了原创内容

http://domain.com/page/thing1 
http://domain.com/page/thing2 
http://domain.com/page/thing3 

我想:

  • 删除/页/从URL
  • 提供来自/ page/thing1的内容

我正在使用Exp ressionEngine,所以这里是我做什么,从URL

<IfModule mod_rewrite.c> 
     RewriteEngine On 

     # Removes index.php 
     RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule ^(.*)$ /index.php/$1 [L] 
</IfModule> 
+0

你不一定必须通过ModRewrite要做到这一点,取决于你如何访问在EE这个数据。这些URL是否通过Pages模块创建?或者'page'是一个模板组,'thing1'是一个模板?或者是'thing1','thing2'等所有入口网址标题? – 2012-01-16 20:39:30

+0

这里有两篇文章可能有助于http://stackoverflow.com/questions/2402140/use-a-subdirectory-as-root-with-htaccess-in-apache-1-3和http://stackoverflow.com/问题/ 990392/htaccess-rewrite-to-redirect-root-url-to-subdirectory – Anagio 2012-01-16 20:55:50

+0

@DerekHogue现在我已经设置了页面是模板组,thing1和thing2是条目。 – Dan 2012-01-16 21:20:40

回答

1

这些新网址有什么收获?

只需去除你的URI /page URL段(即模板组)创造了很多的额外开销和复杂性,说明在以下ExpressionEngine URL Schematic

ExpressionEngine URL Schematic

天然ExpressionEngine Pages Module或第三方Structure Module是最简单的方法,不需要将任何RewriteRules规则添加到您的.htaccess文件中。

但是,这将需要您为创建一个页面每个条目的URL,这可能不太理想。

0

如果你改变你所有的URL中http://domain.com/thing1http://domain.com/thing2等删除的index.php,不能你只需要添加的页/回来,当你重写到index.php文件?

RewriteRule ^(.*)$ /index.php/page/$1 [L] 
+0

这将假设*所有请求*将通过'/ pages'模板组来路由,这会导致很多URI - 包括许多核心ExpressionEngine URL。至少,你必须将'RewriteRule'和'RewriteCond'结合起来。 – rjb 2012-01-17 05:17:58

0

附加现有的重写规则如下这些行IfModule块:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(?!page/)(.*)$ /page/$1 [L,NC]