使用htaccess删除.php扩展名

时间:2017-09-03 12:00:43

标签: regex .htaccess

我有一个网址Console.Write("Please enter a keyword: ") Dim keyword As String = Console.ReadLine() Dim filteredLines As String = String.Join(vbNewLine, System.IO.File.ReadAllLines("C:\a.txt").Where(Function(line As String) line.Contains(keyword)).ToArray()) Console.WriteLine(filteredLines) Console.ReadKey() 我想从网址中删除.php扩展名并转换为example.com/dashboard.php

1 个答案:

答案 0 :(得分:0)

由于您使用的是POST数据,因此建议使用308进行永久重定向,以保留POST数据,而不是使用更常用的301

RewriteEngine On

## hide .php extension
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=308,NE,L]

## To internally redirect /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]