0

目前我正在使用下面的 .htaccess 来删除 .php 扩展名

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

我想在输入时显示页面www.example.com/login.phpwww.example.com/loginwww.example.com/profile=username在输入时显示www.example.com/username

任何建议或答案提前谢谢

4

2 回答 2

2

http://www.9lessons.info/2009/11/pretty-urls-with-htaccess-file.html

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?key=$1

<?php

$key=$_GET['key'];

if($key=='home')
{
include('home.php'); // Home page
}
else if($key=='login')
{
include('login.php'); // Login page
} 
else if($key=='terms')
{
include('terms.php'); // Terms page
}
else 
{
include('users.php'); // Users Gateway
}
?>
于 2012-12-15T14:20:44.267 回答
1

这是另一种选择:

RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)/([\w]+)\.php [NC]

#Select ONE of the following options and DELETE the others
# 1) Without redirection
RewriteRule .*  %1/%2 [L]

# 2) With temporary redirection
RewriteRule .*  %1/%2 [R,L]

# 3) With permanent redirection
RewriteRule .*  %1/%2 [R=301,L]

相应地选择重写规则。

于 2012-12-15T14:27:59.787 回答