久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP/.htaccess:從 url 中刪除 php 擴(kuò)展名

PHP/.htaccess: removing php extension from url(PHP/.htaccess:從 url 中刪除 php 擴(kuò)展名)
本文介紹了PHP/.htaccess:從 url 中刪除 php 擴(kuò)展名的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我使用 .htaccess 代碼刪除了所有網(wǎng)頁的 .php 擴(kuò)展名.這是我使用的代碼:

I was using .htaccess code to remove .php extension for all my web pages. Here's the code I use:

RewriteEngine On
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-s]+)/$ /$1.php

它似乎不起作用.我想我錯過了一些東西.當(dāng)我輸入 www.mysite.com/about/以獲取 www.mysite.com/about.php 時,它返回錯誤 404(未找到頁面).有人可以請說明一下.

It doesn't seem to work. I think I'm missing something. When I type www.mysite.com/about/ to get www.mysite.com/about.php it returns error 404 (page not found). Can someone please shed some light.

謝謝,保羅 G.

推薦答案

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

# If folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# and file exist
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# uncomment the below rule if you want the "/" to be required 
# otherwise leave as is
# RewriteRule ^([^/]+)/$ $1.php [L]
# internally show the content of filename.php
RewriteRule ^([^/]+)/?$ $1.php [L]

以上規(guī)則將:

  1. 如果文件夾存在則不會重定向
  2. 如果文件不存在則不會重定向
  3. 將重定向 / 之前的內(nèi)容,如果存在作為文件名
  1. will not redirect if a folder exist
  2. will not redirect if the file does not exist
  3. will redirect what comes before the / if one is present as the file name

所以它適用于所有這些示例:

So it will work for all these examples:

http://domain.com/about/
http://domain.com/about
http://domain.com/contact/
http://domain.com/contact

如果你愿意,你可以刪除 ?,就像注釋規(guī)則一樣,讓它只接受以 / 結(jié)尾的 URL.

If you want you can remove the ?, like the commented rule, to make it accept only URL's that end with a /.

http://domain.com/about/
http://domain.com/contact/

現(xiàn)在這些是上述工作的重要步驟:

Now these are important step for the above to work:

  1. 它必須進(jìn)入您的根文件夾中的 .htaccess,例如 /home/youraccount/public_html/.htaccess
  2. 重寫規(guī)則前的選項(xiàng)很重要,特別是-MultiViews
  3. 該文件必須與 .htaccess 位于同一位置,例如在您的情況下是 about.php 文件
  4. PHP 必須運(yùn)行正常.
  1. It must go into the .htaccess on your root folder for example /home/youraccount/public_html/.htaccess
  2. The Options before the rewrite rule are very important specially -MultiViews
  3. The file must exist on the same place the .htaccess is for example in your case the about.php file
  4. The PHP must be working obviously.

這篇關(guān)于PHP/.htaccess:從 url 中刪除 php 擴(kuò)展名的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網(wǎng)站的單一入口點(diǎn).壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 午夜资源 | 最新国产精品精品视频 | 黑人精品欧美一区二区蜜桃 | 欧美午夜在线 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 台湾a级理论片在线观看 | 亚洲天堂影院 | 午夜精品久久久久久久星辰影院 | 精品一区欧美 | 中文精品视频 | 日本高清中文字幕 | 99小视频| 九久久 | 一级免费a | 免费成年网站 | 成人免费看 | 91久久精 | 国产欧美精品一区 | 黑人精品xxx一区一二区 | 午夜在线影院 | 欧美欧美欧美 | 国产一在线观看 | www312aⅴ欧美在线看 | 久久久一二三 | 精品久久久久久久久亚洲 | 日韩视频在线播放 | 午夜无码国产理论在线 | 久久国产精品久久 | 成年人在线视频 | 曰批视频在线观看 | 久久久久亚洲精品中文字幕 | 国产高清在线精品 | 中文字幕在线观看一区 | 91在线精品秘密一区二区 | 在线观看免费av网站 | 黑人一级片视频 | 日韩电影一区二区三区 | 久久大陆 | 啪啪免费网 | 日韩不卡在线观看 | 影音先锋中文字幕在线观看 |