2013-12-20 80 views
2

我试图将旧的url结构mysite.com/blog/my-blog-post重写为新的URL结构mysite.com/blog/post/my-blog-post。目前,我有这个规则,我的.htaccess文件:.htaccess URL重写循环

RewriteRule ^blog/(.*)$ /blog/post/$1 [R=301,L] 

这是outputing mysite.com/blog/post/post/post/post/post/post/post/.../my-blog-帖子。

这似乎是我的重写保持mataching,因此再次重写。然后再次。然后再次。我试着补充:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

但是这并没有帮助。我想知道是不是因为这些博客文章来自CMS /数据库而不是真正的文件被指向。

为了使这个博客的新结构更棘手一些,我有类别位于mysite.com/blog/my-category-name。我也有mysite.com/blog/author/author-name。我不想也不需要重写这些网址。这是可行的吗?我是否应该将“类别”一词添加到我的类别网址中以使其更容易?

正如这里参考在我的.htaccess附加重写规则:

# For more awesome .htaccess rules and optimisations 
# checkout the HTML5 Boilerplate .htaccess files 
# https://github.com/paulirish/html5-boilerplate/blob/master/.htaccess 

# Although highly unlikely, your host may have +FollowSymLinks enabled at the root level, 
# yet disallow its addition in .htaccess; in which case, 
# adding +FollowSymLinks will break your setup (probably a 500 error), 
# so just remove it, and your rules should work fine. 
Options +FollowSymlinks 

# EE 404 page for missing pages 
# ErrorDocument 404 /index.php/{ee:404} 

# Simple 404 for missing files 
<FilesMatch "(\.jpe?g|gif|png|bmp|css|js|flv)$"> 
    ErrorDocument 404 "File Not Found" 
</FilesMatch> 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
</IfModule> 

# Blog redirects 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^blog/(.*)$ /blog/post/$1 [R=301,L] 
# RedirectMatch ^/blog/$ /blog/post/$1 [R=301,L] --> Didn't work 

# Block access to "hidden" directories whose names begin with a period. This 
# includes directories used by version control systems such as Subversion or Git. 
<IfModule mod_rewrite.c> 
    RewriteRule "(^|/)\." - [F] 
</IfModule> 

# remove the www - Uncomment to activate 
<IfModule mod_rewrite.c> 
    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
</IfModule> 

# Remove the trailing slash to paths without an extension 
# Uncomment to activate 
<IfModule mod_rewrite.c> 
    RewriteRule ^(.*)/$ /$1 [R=301,L] 
</IfModule> 

# Removes index.php from ExpressionEngine URLs 
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
RewriteCond %{REQUEST_URI} !/system/.* [NC] 
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] 

# Directs all EE web requests through the site index file 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L] 

回答

1

你可以去做具体的检查,下一个路径节点不是/post/

RewriteCond %{REQUEST_URI} !^/blog/post 
RewriteRule ^blog/(.*)$ /blog/post/$1 [R=301,L] 
+0

这个工作大。我还添加了对'/ category'和'/ author'的检查 –