2014-02-27 125 views
1

我想要將我的filename.php更改爲文件名/通過.htaccesss。.htaccess隱藏.php文件擴展名,顯示/(斜槓)而不是

所以,http://labs.ksj-oepites-zomergem.be/info.php#/deleiding 應該成爲http://labs.ksj-oepites-zomergem.be/info/#/deleiding

我有什麼:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

# 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] 

### 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} !-f 
RewriteRule ^([-a-zA-Z0-9]+)\/$ $1.php [L] 

此代碼將改變filename.php和NOT 文件名/

在我的.htaccess中使用此代碼,我的網站將不會作爲標準人。 當我調用一個php文件在javascript中使用ajax ..我得到一個'意想不到的EOF'

任何建議?!的

回答

0

重複: hide .php extension - htaccess

答案有: RewriteEngine敘述在

# Unless directory, remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L] 

# Redirect external .php requests to extensionless url 
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ 
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L] 

# Resolve .php file for extensionless php urls 
RewriteRule ^([^/.]+)$ $1.php [L] 

這是一個重複: hide .php extension - htaccess

這有了答案: 重寫規則^( 。*)$ /$1.php [L]

當隱藏PHP時,我傾向於使用後者,並且增加了使.asp,.html,.cfm和.jsp更改爲.php的規則,因此在服務器上戳一下就不會泄露該技術。也就是說,除非我被客戶要求,否則我不會隱藏它,或者我想創建更短/更漂亮的URL。

相關問題