htaccess为URL添加.html扩展名,带或不带尾部斜线

所以开始我有一个自定义的URL重写,发送请求variables到PHP脚本

重写规则如下:

RewriteRule ^([w/-]+)(?.*)?$ test/index.PHP?slug=$1 [L,T=application/x-httpd-PHP]

所以,如果你访问类似domain.com/slug-text东西,它会发送slug-text到位于名为test的文件夹中的index.PHP

我想要的是我所有的url看起来像domain.com/slug-text.html ,但是slug-testvariables仍然应该发送到index.PHP文件

.htaccess mod_rewrite不能在子目录中工作

ErrorDocument 404 /404.PHPPHP中的.htaccess文件中不起作用

如何阻止通过IP访问一组url模式?

将非www和非httpsredirect到https:// www

htaccess重写URL的PHP参数

我无法弄清楚的是redirect。 我希望将所有旧的url从domain.com/slug-text或domain.com/slug-text/redirect到domain.com/slug-text.html并将slug-text发送到位于test文件夹中的index.PHP文件

search了很多,但无法在互联网上的任何地方find这个问题的答案。

谢谢大家的帮助。

更新:我的新代码是:

RewriteEngine On Options +FollowSymlinks RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-l RewriteRule ^(([w/-]+)?[w-])(?!:.html)$ http://domain.com/$1.html [L,R=301] RewriteRule ^(([w/-]+)?[w-])(/|.html)?$ test/index.PHP?slug=$1 [L]

domain.com/slug-text/没有被redirect到domain.com/slug-text.html domain.com/slug-text按预期redirect到domain.com/slug-text.html

我需要改变什么?

简单的.htaccess子域重写

htaccessredirectwww到非www而不改变地址

如何创build一个友好的URL与两个或更多的参数使用国防部重写/ htaccess?

从HTTP切换到HTTPS,失去了所有Facebook的“喜欢”

Apache重写URL中的string – 障碍在查询中是“?”

这条规则:

RewriteRule ^(([w/-]+)?[w-])(/|.html)?$ test/index.PHP?slug=$1 [L]

将陷阱domain.com/slug-text和domain.com/slug-text.html并发送slug-text到/test/index.PHP里面的/test/index.PHP帕拉姆。

如果你真的想重新使用从旧的网址[R=301]到新的然后使用这个:

RewriteRule ^(([w/-]+)?[w-])/?(?!:.html)$ http://domain.com/$1.html [L,R=301] RewriteRule ^(([w/-]+)?[w-]).html$ test/index.PHP?slug=$1 [L]

另外请注意,因为使用明确的重定向底部规则被修改,以.html陷阱网址的结尾

这也是可取的(如果你的.htaccess还没有包含这个)过滤现有文件文件夹的条件不被你的重定向规则困住。 只需在RewriteRule行之前添加这些行:

# existing file RewriteCond %{SCRIPT_FILENAME} !-f # existing folder RewriteCond %{SCRIPT_FILENAME} !-d

如果使用符号链接

# enable symlinks Options +FollowSymLinks # existing symlink RewriteCond %{SCRIPT_FILENAME} !-l

//另外

你的.htaccess文件应该是这样的:

RewriteEngine on Options +FollowSymLinks RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-l RewriteRule ^(([w/-]+)?[w-])/?(?!:.html)$ http://domain.com/$1.html [L,R=301] RewriteRule ^(([w/-]+)?[w-]).html$ test/index.PHP?slug=$1 [L]

这应该是重定向/ slug-text到/slug-text.html

RedirectMatch ^/([w-]+)/?$ http://domein.com/$1.html

当slug-text只有字母,数字, – 和_时就是这种情况。 将slug-text.html重写为一个PHP文件,并将该slu pass作为参数传递:

RewriteRule ^([w-]+).html$ test/index.PHP?slug=$1 [R,L]

如果你的.htaccess中有两个行,第一个将执行从旧URL重定向到新的和第二个将处理请求。

相关文章

可以认为OpenFeign是Feign的增强版,不同的是OpenFeign支持S...
为进一步规范小程序交易生态、提升用户购物体验、满足用户在...
云原生之使用Docker部署Dashdot服务器仪表盘
本文主要描述TensorFlow之回归模型的基本原理
1.漏洞描述Apache Druid 是一个集时间序列数据库、数据仓库和...
内部类(当作类中的一个普通成员变量,只不过此成员变量是cl...