【问题标题】:.htaccess hide .php file extension, show /(slash) instead.htaccess 隐藏 .php 文件扩展名,改为显示 /(斜线)
【发布时间】:2014-03-31 11:52:27
【问题描述】:

我想通过 .htaccesss 将我的 filename.php 更改为 filename/

所以,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 更改为 filename 而不是 filename/

在我的 .htaccess 中使用此代码,我的网站将无法正常工作。 当我在 javascript 中使用 ajax 调用 php 文件时。我得到一个“意外的 EOF”

有什么建议吗?!

【问题讨论】:

    标签: javascript php .htaccess


    【解决方案1】:

    重复: hide .php extension - htaccess

    答案是: 重写引擎开启

    # 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,否则我不会隐藏它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 2017-10-06
      • 2013-03-13
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多