【问题标题】:Add url segment in specific domain using rewrite rule .htaccess apache使用重写规则 .htaccess apache 在特定域中添加 url 段
【发布时间】:2017-06-20 13:35:14
【问题描述】:

我有这样的网址

mydomain.com

但是当我访问它时,我想将它重写到这个 url

mydomain.com/news

其他情况,我想要这样

mydomain.com/read/1 -> mydomain.com/news/read/1

mydomain.com/view?cat=sport -> mydomain.com/news/view?cat=sport

我的代码是这样的

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/news/$1 [QSA,NC]

但是还是不行。它不会在下一个 url 段中添加“新闻”。 请建议我如何在 .htaccess 中为此编写重写规则? 我对我的英语感到抱歉

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    将您的代码替换为以下内容:

    RewriteEngine on
    RewriteRule !^news /news%{REQUEST_URI} [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      相关资源
      最近更新 更多