[英]How do I restructure the htaccess to allow for the home page?
Ok so I have a site that has tons of pages and I want to create a php file fore each one...this works great..here is what i have, code wise好的,所以我有一个有大量页面的网站,我想为每个页面创建一个 php 文件......这很好用......这就是我所拥有的,代码明智的
Here is my htaccess这是我的 htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]
here is my index.php file这是我的 index.php 文件
$parts = explode('/', $_REQUEST['url']);
switch ($parts[count($parts) - 1]) {
case 'restaurant':
include "pages/restaurant.php";
break;
case 'retail':
include "pages/retail.php";
break;
.......
.......
}
this works great and if i visit the url http://someurl.com/restaurant
the proper file in pages/restaurant.php pulls up.这很好用,如果我访问 url http://someurl.com/restaurant
页面/restaurant.php 中的正确文件。 The only problem is the home page http://someurl.com
when i visit it i get a:唯一的问题是主页http://someurl.com
当我访问它时,我得到一个:
Forbidden
You don't have permission to access /structure on this server.
Is there a way to fix this in the .htaccess to address this issue and should i create a file maybe called home.php in the pages folder or should i just put the content of the home page in the index file in an else condition...any ideas有没有办法在 .htaccess 中解决这个问题来解决这个问题,我应该在页面文件夹中创建一个名为 home.php 的文件,还是应该将主页的内容放在索引文件中的其他条件下。 。有任何想法吗
You forgot to specify a default switch case?您忘记指定默认开关盒?
switch ($parts[count($parts) - 1]) {
case 'restaurant':
include "pages/restaurant.php";
break;
case 'retail':
include "pages/retail.php";
break;
default:
include "pages/default_page.php";
break;
.......
.......
}
1. Use this rule somewhere before existing rules: 1. 在现有规则之前的某处使用此规则:
RewriteRule ^$ index.php?url=home [L]
2. Create pages/home.php
2.创建pages/home.php
3. Add this to your switch statement: 3. 将此添加到您的 switch 语句中:
case 'home':
include "pages/home.php";
break;
PS I do not recommend using default:
to handle home page. PS我不推荐使用default:
来处理主页。 default:
should be used to handle 404 page / unknown pages ONLY . default:
仅用于处理 404 页面/未知页面。
Do you have a default
statement in that switch
?您在该switch
中有default
语句吗? My bet is you don't.我敢打赌你不会。
DirectoryIndex index.php
Do you have this code in your httpd.conf or .htaccess?您的 httpd.conf 或 .htaccess 中有此代码吗?
It seems like your default file is not index.php您的默认文件似乎不是 index.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.