phpで書かれたファイルをURI(URL)で拡張子なしにしていく方法について記述していきます。 http://www63.atwiki.jp/nicepaper/index.phpならhttp://www63.atwiki.jp/nicepaper/indexでアクセスできるようにしていきます。10月3日記事

目次





.htaccessの編集

テキストエディタを開いて、

Options +MultiViews
AddType text/html .php

と記述し、.htaccessというファイル名で保存。

テスト

index.php

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>index.php</title>
</head>

<body>
<div>
    <form action="post" method="post"><!--action="post.php"ではなく、postのみでよい。-->
        <label for="text">文字</label>
        <input type="text" name="text">
    	<input type="submit" name="submit" value="送信">
    </form>
</div>
<div>
	<p><a href="get?id=10">リンク</a></p>
</div>
</div>
</body>
</html>

post.php

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>post.php</title>
</head>
<body>
<?php
$text = $_POST["text"];
echo $text;
?>
</body>
</html>

get.php

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>get.php</title>
</head>
<body>
<?php
$id = $_GET["id"];
echo $id;
?>
</body>
</html>



まとめ

.phpを隠すなんてお行儀悪いという人もいれば、セキュリティ対策のために必要だという人もいます。 ご自由にどうぞ。

以上

最終更新:2015年10月02日 23:37