簡體   English   中英

從URL Apache刪除.php

[英]Removing .php from URL Apache

我的網站目錄結構如下:

/var/www/html/wordpress/
/var/www/html/rail/

訪問www.example.com時, /wordpress/是我的默認網站。 WordPress包含wp自動創建的.htaccess

/rail/sites-enabled Apache sites-enabled的別名,可從www.example.com/rail訪問

/rail/文件內容具有文件擴展名.php ,但是出於用戶體驗的目的,此地址顯示在我不想要的地址欄中。 我想要/rail/search/(future)/search/parameters/而不是/rail/search.php/future/search/parameters/

我已經閱讀了有關.htaccess納米化的其他堆棧溢出支持主題,但是我的htaccess位於wordpress 我需要在/ rail /內創建另一個.htaccess嗎?

從.php文件中刪除.php文件exension的最佳方法是什么,這樣我的URL結構是無縫的,就像wordpress一樣,而不會得到笨拙的.php? 提前致謝。

在您的VirtualHost(apache)文件中以及使用別名的位置中,所做的更改很少。

DocumentRoot /var/www/html/wordpress
Alias /rail "/var/www/html/rail"
<Directory "/var/www/html/rail">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

使用以下代碼通過在/rail/目錄中創建.htaccess文件,從/rail/目錄的URL中刪除.php擴展名。

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /rail/

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM