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

在 url mod_rewrite 中隱藏擴展名 .php

hide extension .php in url mod_rewrite(在 url mod_rewrite 中隱藏擴展名 .php)
本文介紹了在 url mod_rewrite 中隱藏擴展名 .php的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 PHP 網(wǎng)站,我正在嘗試隱藏擴展程序.我通過谷歌找到了一些東西,但它們似乎都太復雜了,或者它們將 index 重定向到 index.php:就像你寫 name.com/contact 它轉(zhuǎn)到 name.com/contact.php.我不想那樣,我只想:

I have a website in PHP, and I'm trying to hide the extension. I've found a couple of things via Google, but they all seem to be too complicated, or they redirect index to index.php: like if you write name.com/contact it goes to name.com/contact.php. I don't want that, I just want:

    www.name.com/es/index.php       to be www.name.com/es/inicio
    www.name.com/es/empresa.php     to be www.name.com/es/empresa
    www.name.com/es/productos.php   to be www.name.com/es/productos
    www.name.com/es/clientes.php    to be www.name.com/es/clientes
    www.name.com/es/recetas.php     to be www.name.com/es/recetas
    www.name.com/es/contacto.php    to be www.name.com/es/contacto

    www.name.com/en/index.php       to be www.name.com/en/home
    www.name.com/en/company.php     to be www.name.com/en/company
    www.name.com/en/products.php    to be www.name.com/en/products
    www.name.com/en/clients.php     to be www.name.com/en/clients
    www.name.com/en/recepis.php     to be www.name.com/en/recepis
    www.name.com/en/contact.php     to be www.name.com/en/contact

/en/ 文件夾是英文版,/es/ 文件夾是西班牙文版

the /en/ folder is English version and the /es/ folder is the Spanish version

網(wǎng)站內(nèi)的鏈接也沒有擴展名.

Also the links inside the website, would be also without the extension.

例如,鏈接到 clientes 的圖像將是 clientes 而不是 clientes.php 如果有人嘗試轉(zhuǎn)到 /page.php,它仍然有效,但會重定向到 /page.

E.g, an image linked to clientes would be clientes and not clientes.php and if somebody tries to go to /page.php, it still works but it redirects to /page.

推薦答案

htacces 文件應(yīng)該是這樣的:

The htacces file should look like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

您重定向 url 中具有相同名稱的任何 php 文件而沒有php".
然后在您的 php 文件中,您可以檢查 url 是否包含擴展名 (http://blabla.com/bla.php) 并將頁面重定向到?jīng)]有擴展名的相同頁面.
所以,在每個 php 文件的開頭,你應(yīng)該調(diào)用這個函數(shù):

You redirect any php file in the url with the same name withouth the "php".
Then in your php files, you can check to see if the url contains the extension (http://blabla.com/bla.php) and redirect the page to the same one withouth the extension.
So, at the beginning of each php file you should call this function :

function redirectIfNeeded(){
    $url = $_SERVER["REQUEST_URI"];
    if(preg_match("/.php/$", $url))
        header("Location: ".preg_replace("/.php/",$url));
}

這篇關(guān)于在 url mod_rewrite 中隱藏擴展名 .php的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)站的單一入口點.壞的?好的?沒問題?)
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 示例)
主站蜘蛛池模板: 狠狠操在线 | 亚洲欧洲中文 | 欧美视频在线看 | 成人深夜小视频 | 日本福利视频免费观看 | a在线观看 | 国产乱码精品一区二三赶尸艳谈 | 中文字幕电影在线观看 | 在线免费观看成年人视频 | 狠狠操电影 | 日韩中文字幕在线观看视频 | 91pron在线| 狠狠爱视频 | 99reav| a网站在线观看 | 亚洲成av | 色888www视频在线观看 | 国产视频一视频二 | 一区二区三区国产 | 免费一级欧美在线观看视频 | 国产欧美久久精品 | 能看的av网站 | av色站| www亚洲一区 | 天堂三级 | 久久国产精品免费视频 | 国产日韩一区二区三区 | 一级黄色毛片子 | 欧美a在线 | 91视频大全 | av网站在线播放 | 香蕉一区| 日操操 | 国产伦精品一区二区三区精品视频 | 国产一级大片 | 夜夜操天天操 | 91精品国产美女在线观看 | 欧美精品久久久 | 伊人二区 | 精品视频在线观看 | 国产精品黄 |