简体   繁体   English

使用重写规则 .htaccess apache 在特定域中添加 url 段

[英]Add url segment in specific domain using rewrite rule .htaccess apache

I have url like this我有这样的网址

mydomain.com mydomain.com

But when I access it, I want rewrite it to this url但是当我访问它时,我想将其重写为这个 url

mydomain.com/news mydomain.com/新闻

In other case, I want it like this在其他情况下,我想要这样

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

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

My code is like this我的代码是这样的

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

But it still not work.但它仍然不起作用。 It is not add "news" in next url segment.它不是在下一个 url 段中添加“新闻”。 Please suggest how I can write a rewrite rule for this in .htaccess?请建议我如何在 .htaccess 中为此编写重写规则? I am sorry about my English我很抱歉我的英语

Replace your code with the following :将您的代码替换为以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM