繁体   English   中英

使用 htaccess 从 index.php 重定向到 another.php 文件

[英]Redirect with htaccess from index.php to another.php file

我想创建漂亮的网址。 但是,我在 .htaccess 中遇到了一些问题。 例如我有 url domain/some.php?f=query-string 我想更改域/查询字符串(预期的 url)。 是否可以通过 .htaccess 更改/重定向。 或者也许来自 php 文件本身。

这是我制作的一些 htaccess 片段,但我得到了空白/错误页面

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    RewriteRule ^/([^/.]+)$ some.php?f=$1    [NC,L]
</IfModule>

感谢您的关注。

RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]

.htaccess ,由RewriteRule模式匹配的 URL-path 不以斜杠开头,因此上面的内容永远不会匹配并且什么也不做。 这应该像下面这样写:

RewriteRule ^([^/.]+)$ some.php?f=$1 [L]

此处不需要NC标志,因为正则表达式已经“不区分大小写”。

暂无
暂无

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

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