2015-11-24 73 views
2

我有我的服务器上的以下几种情况:htaccess的检查,如果空的查询字符串

/-> 
    news-> 
    .htaccess 
    index.php 
    post.php 
... 

而在我的.htaccess以下规则:

RewriteRule ^(.*)/admin   post.php?slug=$1&admin_mode=true   [NC,QSA,L] 
RewriteRule ^(.*)$    post.php?slug=$1       [NC,QSA,L] 

现在我需要我的网址是以下:

如果要求www.mydomain.com/news/ - >它应该得到的index.php文件

如果要求www.mydomain.com/friendly-title-of-my-article - >它 应该得到post.php文件的查询字符串,如我的.htaccess所示。

目前我得到正确的查询字符串的post.php中,但是当我去www.mydomain.com/news/,它的请求post.php中的文件。

请帮忙。谢谢

回答

1

创建好路由的一种方法是让一切都转到index.php并控制那里的流量。它具有多种优势,例如能够查询数据库,然后决定要加载的页面。这可以很好地影响SEO。

2

使用此

#if query string is empty 

RewriteCond %{QUERY_STRING} ^$ 

#match on/for root, or .index.php in request and send to query string version 

RewriteRule ^(/|index.php)?$ /index.php?step=1 [R=301,L] 
+0

已经尝试过..它要求www.example当得到我http://example.com/var/www/site/news/index.php?step=1。 COM /新闻/ – somonek