-1

我正在尝试使用 .htaccess 来更改 url 并使用 php 包含页面

旧:http ://website.com?page=test

新:http ://website.com/test

<?php include 'pages/'. $_GET['page'] . '.php'; ?>

我不知道从哪里开始 .htaccess 但任何帮助都会很棒,谢谢:]

4

2 回答 2

0

试试这个,用户应该看到这个,http://domain.com/thepage服务器会将请求理解为http://domain.com/?page=thepage

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteRule ^([^/]*)$ ?page=$1 [NC,L]
</IfModule>
于 2013-07-02T03:17:45.280 回答
0
<?php include 'pages/'. $_GET['page'] . '.php'; ?>

单独对黑客非常友好。您应该首先将选项限制为允许的文件。即在内部点击/index.php 并预设一系列有效选项。也就是说,根据文件的数量,预设硬代码可能是您的最佳选择。

我相信你的意思是 mod_rewrite。 http://httpd.apache.org/docs/current/rewrite/remapping.html

添加到 /.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^page=test$ [NC]
RewriteRule . /test [NC,L,R=301]
</IfModule>

或更动态

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^page=(.*)$ [NC]
RewriteRule . /%1/ [NC,L,R=301]
</IfModule>

我最好的建议是在内部将所有内容发送到 /index.php,然后通过一些 php 解析/验证,发送到有效选项的 switch() 和安全默认值:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
</IfModule>
于 2013-07-02T02:47:38.893 回答