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

如何使用 Apache Mod_rewrite 刪除 php 擴展,同時保留

How to use Apache Mod_rewrite to remove php extension, while preserving the GET parameters?(如何使用 Apache Mod_rewrite 刪除 php 擴展,同時保留 GET 參數?)
本文介紹了如何使用 Apache Mod_rewrite 刪除 php 擴展,同時保留 GET 參數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我試圖從我的網站中刪除 PHP 擴展.當用戶請求一個 PHP 文件時,PHP 將被刪除并且用戶將被重定向,當用戶輸入一個沒有 PHP 的 URL 時,將提供實際的 PHP 文件.這很有效,除非 URL 中有 GET 參數.我的規則如下:

I was trying to remove the PHP extensions from my website. When user requests a PHP file, the PHP will be removed and the user will be redirected, and when the user types in an URL without PHP, the actual PHP file will be served. This worked well except when there is GET parameter in the URL. My rules are as below:

# remove .php ONLY if requested directly
RewriteCond %{THE_REQUEST} (.phpsHTTP/1)
RewriteRule ^(.+).php$ /$1 [R=301,L,QSA]

# remove trailing slash ONLY if it is not an existing folder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# rewrite to FILENAME.php if such file does exist and is not a folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L,QSA]

我認為即使有任何 GET 參數,這也應該已經能夠刪除 php,但它失敗了.我也試過這樣的:

I thought this should already be able to remove php even when there is any GET parameter, but it failed. I also tried something like this:

RewriteCond %{THE_REQUEST} (.phpsHTTP/1)
RewriteRule ^(.).php(.)$ $1$2 [R=301,L,QSA]

也沒用,php還在.但如果我嘗試:

It also didn't work, the php is still there. But if I try:

RewriteRule ^(.).php(.)$ $1$2 [R=301,L,QSA]

即,移除 RewriteCond,php 擴展被移除,參數被保留,但頁面不會被提供,因為瀏覽器說有太多的重定向.

ie, removing the RewriteCond, the php extension gets removed and the parameters were preserved, but the page won't be served as the browser says there were too many redirects.

有人有什么想法嗎?

推薦答案

感謝 SteAp 的回答.剛好我現在能想出一個辦法來處理它,想在這里分享一下,以防其他人遇到類似的問題.

Thank you SteAp for your answer. I happened to be able to figure out a way to deal with it just now, and would like to share here in case others run into similar problems.

在我的規則中,我有

# remove .php ONLY if requested directly
RewriteCond %{THE_REQUEST} (.phpsHTTP/1)
RewriteRule ^(.+).php$ /$1 [R=301,L,QSA]

當用戶請求一個 PHP 文件時執行外部重定向.這里的 RewriteCond 是為了防止重定向循環——即由于內部重寫和外部重定向不當而導致的無限重定向(刪除 php,然后添加 php,然后再次刪除,...)

To execute external redirect when user requests a PHP file. The RewriteCond here is to prevent redirect loops - ie, endless redirect due to improper internal rewrite and external redirect (removing php, then adding php, then remove again, ...)

當有參數時,實際的標題為 http://domain.com/file.php?.... HTTP/1.1像這樣的東西,所以 RewriteCond 中的模式將不起作用,因為它沒有考慮參數.

When there are parameters, the actual header comes as http://domain.com/file.php?.... HTTP/1.1 Something like this, so the pattern in the RewriteCond won't work since it didn't take parameters into account.

要解決它,只需將上面的代碼替換為:

To solve it, simply replace the above code with:

# remove .php ONLY if requested directly
RewriteCond %{THE_REQUEST} (.php(.*)sHTTP/1)
RewriteRule ^(.+).php$ /$1 [R=301,L,QSA]

通過這樣做,參數可以被模式匹配,現在一切正常.

By doing so, the parameters can be matched by the pattern, and now everything works.

希望這能幫助有類似問題的人(或者它只是像我這樣的菜鳥?lol)

Hope this will help someone having similar problem (or is it just a noob like me? lol)

這篇關于如何使用 Apache Mod_rewrite 刪除 php 擴展,同時保留 GET 參數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 久久草在线视频 | 正在播放一区二区 | 中文字幕免费视频 | 国产jizz女人多喷水99 | 美国av片在线观看 | 国产亚洲精品久久久久久豆腐 | 欧美日一区二区 | av中文字幕在线观看 | 国产精品久久精品 | 五月综合久久 | 欧美日一区二区 | 欧美在线播放一区 | 久久久久www | 国产视频欧美 | 精品在线 | 日韩欧美精品在线播放 | 国产免费看| 亚洲视频在线看 | www国产亚洲精品 | 欧洲毛片 | 在线播放国产一区二区三区 | 国产在线不卡视频 | 一区二区在线免费观看 | 欧美成人自拍视频 | 久久新| 久久亚洲天堂 | 91在线观看| 亚洲在线一区二区 | 久久99精品久久久久久国产越南 | 国产精品久久久久久久久久久久久久 | 亚洲一区视频在线 | av电影一区| 欧美日韩成人影院 | 国产一区999 | 欧美a√ | 国产一区二区三区四区五区加勒比 | 国产午夜精品久久久久免费视高清 | 男人的天堂久久 | 精品一二三区在线观看 | 91短视频网址 | 久久精品久久久 |