简体   繁体   English

.htaccess隐藏.php文件扩展名,而是显示/(斜杠)

[英].htaccess hide .php file extension, show /(slash) instead

I want to change my filename.php to filename/ through .htaccesss. 我想通过.htaccesss将我的filename.php更改为filename /

So, http://labs.ksj-oepites-zomergem.be/info.php#/deleiding should become http://labs.ksj-oepites-zomergem.be/info/#/deleiding 因此, http://labs.ksj-oepites-zomergem.be/info.php#/deleiding应该成为http://labs.ksj-oepites-zomergem.be/info/#/deleiding

What I've got: 我所拥有的:

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]

This code will change filename.php to filename and NOT filename/ 此代码会将filename.php更改为filename,而不是filename /

Using this code in my .htaccess, my site won't work as normal. 在我的.htaccess中使用此代码,我的网站将无法正常工作。 When I call a php file using ajax in javascript.. I get an 'Unexpected EOF' 当我在JavaScript中使用Ajax调用php文件时。我得到了“意外的EOF”

Any suggestions?! 有什么建议么?!

Duplicate of: hide .php extension - htaccess 复制: 隐藏.php扩展名-htaccess

The answer there was: RewriteEngine On 答案是:RewriteEngine On

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

And that was a duplicate of: hide .php extension - htaccess 那是重复的: hide .php扩展名-htaccess

Which had the answer: RewriteRule ^(.*)$ /$1.php [L] 答案如下:RewriteRule ^(。*)$ /$1.php [L]

When hiding PHP, I tend to do the latter, with added rules for making .asp, .html, .cfm and .jsp also rewrite to the .php, so poking at the server shouldn't reveal the tech. 当隐藏PHP时,我倾向于使用后者,并增加了使.asp,.html,.cfm和.jsp重写为.php的规则,因此在服务器上戳戳不应该揭示技术。 That said, I don't tend to hide it unless I'm asked to by a client, or I want to create shorter/prettier URLs. 就是说,除非有客户要求,否则我不会倾向于隐藏它,或者我想创建更短/更漂亮的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM