删除“index.php?page=文件名”

发布于 2024-11-08 14:27:25 字数 826 浏览 0 评论 0原文

我希望我的网站看起来像这样: http://www.example.com/about 而不是 web_url/index[dot]php?page=关于

在我的index[dot]php里面,我的导航链接是这样的:

<a href="index[dot]php?page=about">about</a>
etc.
...
$view = $_GET['page'];
switch($view){
 case 'about':
 include("pages/about.html");
 break;

 case 'project':
 include("pages/project.html");
 break;

... and so on
}

/* I have tried edit .htaccess file */
like this:
order allow,deny
allow from all


Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ websiteurl/$1 [R=301,L]

请帮忙!

谢谢, 别名

I would like my site looks like this:
http://www.example.com/about instead of web_url/index[dot]php?page=about

Inside my index[dot]php, my navigation links like this:

<a href="index[dot]php?page=about">about</a>
etc.
...
$view = $_GET['page'];
switch($view){
 case 'about':
 include("pages/about.html");
 break;

 case 'project':
 include("pages/project.html");
 break;

... and so on
}

/* I have tried edit .htaccess file */
like this:
order allow,deny
allow from all


Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ websiteurl/$1 [R=301,L]

Please help!

Thanks,
Alias

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒浓于脸红 2024-11-15 14:27:25

这就是我所做的:

RewriteEngine  on
RewriteRule    ^[^/.]*$  /run.php [L]

然后我有一个文件 run.php,它可以根据全局变量计算文件路径:

 $basename = $_SERVER['REDIRECT_URL'];
 $basename = ereg_replace('.*/', '', $basename);
 $basename = ereg_replace('\.html

然后您可以将其包含在内,将其作为模板读取,无论您做什么。

, '', $basename); if($basename == '') { $basename = 'index'; } $html_file = "$basename.html"; $php_file = "$basename.php";

然后您可以将其包含在内,将其作为模板读取,无论您做什么。

Here's what I do:

RewriteEngine  on
RewriteRule    ^[^/.]*$  /run.php [L]

then I have a file run.php that calculates the file paths from the globals:

 $basename = $_SERVER['REDIRECT_URL'];
 $basename = ereg_replace('.*/', '', $basename);
 $basename = ereg_replace('\.html

Then you can include that, read it as a template, whatever you do.

, '', $basename); if($basename == '') { $basename = 'index'; } $html_file = "$basename.html"; $php_file = "$basename.php";

Then you can include that, read it as a template, whatever you do.

梦情居士 2024-11-15 14:27:25

试试这个:

$view = $_SERVER[REQUEST_URI];
switch($view){
 case 'about':
 include("pages/about.html");
 break;
...
}

$_SERVER[REQUEST_URI] 将获取 http 主机 url 之后的 URI 段,因此

www.example.com/uri -> $_SERVER[REQUEST_URI] == "uri"

try this:

$view = $_SERVER[REQUEST_URI];
switch($view){
 case 'about':
 include("pages/about.html");
 break;
...
}

$_SERVER[REQUEST_URI] will get the URI segment after the http host url, hence

www.example.com/uri -> $_SERVER[REQUEST_URI] == "uri"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文