-1

我正在尝试.php从我网站上的文档中删除文件扩展名,因此 URL 会像这样:
http
://www.mysite.com/home/ 而不是这样:
http ://www.mysite.com/主页.php

我已经尝试了各种 mod_rewrite 代码,除了这个之外,没有一个对我有用:

#Enable rewrite engine
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.mysite.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.mysite.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

我对此一无所知.htaccess,而且我是 php 新手,所以我基本上无法弄清楚这一点。目前这是隐藏的,.php但它以原始格式/文本喷出页面 php 内容,而不是像这样执行:

<?php
    $page_title = "Home";
    include('includes/header.php'); 
    include('includes/mod_home/mod_intro.php');
    include('includes/copyrightbar.php'); 
    include ('includes/mod_login/login_form.php');
    include('includes/mod_home/mod_welcome.php');
    include('includes/mod_home/mod_platinum.php');

?>

<?php include('includes/mod_home/mod_starlight.php'); ?>
<?php include('includes/mod_home/mod_diamond.php'); ?>
<?php include('includes/mod_home/mod_newest.php'); ?>
<?php include('includes/mod_home/mod_featured.php'); ?>
<?php include('includes/mod_home/mod_gold.php'); ?>


<?php include('includes/footer.php'); ?>

为什么会这样?我已经遵循了所有在线教程,其他所有人似乎都没有这样的问题。我的服务器确实支持.htaccess并且正在运行 Linux。
例如,我的链接仍然指向home.php(我需要更改这些吗?)

4

1 回答 1

0

你错过的是RewriteBase命令。
这是代码:

#Start rewriting after /
RewriteBase /
#ignore real directories
RewriteCond %{REQUEST_FILENAME} !-d
#ignore real files
RewriteCond %{REQUEST_FILENAME} !-f
#Rewrite the match to .php file
RewriteRule ^(.*)$ $1.php [QSA,L]

可能有一些原因 PHP 没有被执行。所以,当然,试试这个:

AddType application/x-httpd-php .php

您可以改写为 GET paremater 页面,就像这样:

RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
于 2013-02-13T14:35:03.250 回答