【发布时间】:2014-11-08 07:55:44
【问题描述】:
我确实使用 htaccess 来重定向某些页面 301
但它做了一些奇怪的重定向。
为了确定它是否不在我的代码中,我只是放了一个空文件 index.php
但我得到了相同的结果
当我调用 mywebsite.com/accueil.html 时,它会重定向到 mywebsite.com/?p=accueil
这不是我所期望的。
我还删除了那个 301 重定向,但它仍然重定向到这个。
下面是我的htaccess
Options +FollowSymLinks
RewriteEngine on
#Pages principale après index.php?p=ma-page
RewriteRule ^([^/]*)\.html$ index.php?p=$1 [L]
#Page de visualisation des chantiers
RewriteRule ^chantier/([^/]*)/([^/]*)\.html$ index.php?
p=chantier&id=$1&titre=$2 [L]
#Page de demande de devis
RewriteRule demande-devis/([^/]*)/([^/]*)\.html$ index.php?
p=demande-devis&type=$1&categorie=$2 [L]
#Le permis de construire
RewriteRule permis-de-construire/([^/]*)/([^/]*)\.html$ index.php?
dossier=permis-de-construire&fichier=$1&p=$2 [L]
#Maisons en bois page générale
RewriteRule maisons-en-bois/([^/]*)\.html$ index.php?p=maisons-en-
bois&module=$1 [L]
#Détail maisons en bois
RewriteRule maisons-en-bois/voir-detail/([^/]*)/([^/]*)/([^/]
*)\.html$ index.php?p=maisons-en-bois&module=voir-
detail&categorie=$1&id=$2&name=$3 [L]
#Maisons en bois par categories
RewriteRule maisons-en-bois/nos_modeles/([^/]*)\.html$ index.php?
p=maisons-en-bois&module=nos_modeles&categorie_home=$1 [L]
#Demande de devis sans categorie
RewriteRule demande-devis/([^/]*)\.html$ index.php?p=demande-
devis&type=$1 [L]
#Articles du blog à lire
RewriteRule lire-article/([^/]*)/([^/]*)\.html$ index.php?p=lire-
article&id=$1&titre=$2 [L]
#404
ErrorDocument 404 /404.html
#301
Redirect 301 /home.html /accueil.html
Redirect 301 /default.html /accueil.html
Redirect 301 /index.html /accueil.html
任何形式的 pf 帮助将不胜感激。
编辑:以下功能似乎是问题
function www() {
$protocol = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if ($_SERVER['REQUEST_URI'] == '/' || empty($_SERVER['REQUEST_URI']) || is_null($_SERVER['REQUEST_URI'])) {
if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.') {
header('Location: ' . $protocol . 'www.' . $_SERVER['HTTP_HOST']);
exit;
}
} else {
if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.') {
header('Location: ' . $protocol . 'www.' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit;
}
}
}
function trail() {
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if (substr($url, -1) == '/') {
$url2 = rtrim($url, '/');
header('location:' . $url2);
}
}
【问题讨论】:
-
重定向永远不会发生,因为第一条规则将执行重写
RewriteRule ^([^/]*)\.html$ index.php?p=$1 [L]。
标签: php apache .htaccess mod-rewrite redirect