gpt4 book ai didi

apache - .htaccess php 中的重定向规则

转载 作者:行者123 更新时间:2023-12-04 01:04:56 24 4
gpt4 key购买 nike

我想将此 URL http://www.example.com/blog/Title-here 重定向到我的 blog.php 页面

请注意Title-here 可以是任何内容。

我该怎么做?

我正在尝试关注,但它不起作用。

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/?$ blog.php [NC,L]

我不知道为什么。

以下是我的完整 .htaccess 代码,可能是这里的问题。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/?$ product.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/?$ results.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ results.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/?$ blog.php [NC,L]

ErrorDocument 404 http://www.example.com/404.php

最佳答案

根据您展示的示例,您能否尝试以下操作。由于您使用的是非常通用的正则表达式(未在其中提供任何 uri 条件),因此它没有达到您博客页面的最后一条规则。将其作为您的第一条规则,如下所示。我还在所有现有规则中修复了您的正则表达式。

请确保在测试您的 URL 之前清除您的浏览器缓存。

###Making Rewriteengine ON here.
RewriteEngine ON

##Placing rule for URIs starting from blog here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog blog.php [NC,L]

##Placing rule for url like: http://localhost:80/test1/test2/test3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/(?:[^/]*)/(?:.*)/?$ product.php [L]

##Placing rule for url like: http://localhost:80/test1/test2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/(?:.*)/?$ results.php [L]

##Placing rule for url like: http://localhost:80/test1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ results.php [L]

ErrorDocument 404 http://www.example.com/404.php

关于apache - .htaccess php 中的重定向规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66834602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com