首頁>Program>source

我想放些东西 將隱藏 .htaccess的檔案 我的php檔案的檔案擴充套件名,因此轉到www.example.com/dir/somepage会將其顯示為www.example.com/dir/somepage.php。

有没有可行的解決方案? 如果這很重要,我的網站將使用HTTPS。

這是我目前的.htaccess:

.php
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] ErrorDocument 404 /error/404.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.php [L]
最新回復
  • 5月前
    1 #

    在DOCUMENT_ROOT下的.htaccess中使用以下代碼:

    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]
    

  • 5月前
    2 #

    Remove php extension

    您可以使用/.htaccess中的代碼:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^ %{REQUEST_FILENAME}.php [NC,L]
    

    使用上面的代碼,您將可以/file.php身份訪問/file.php

    Remove html extension

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^ %{REQUEST_FILENAME}.html [NC,L]
    

    註意:每次htaccess都應在頂部使用一次'RewriteEngine on'指令,因此,如果要組合這2條規則,只需从第二條規則中删除该行即可.您還可以删除您選擇的任何其他擴充套件名,只需在代碼上將.php替換為它们即可.

    Happy htaccessing!

  • 5月前
    3 #

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f       # if the requested URL is not a file that exists
    RewriteCond %{REQUEST_FILENAME} !-d       # and it isn't a directory that exists either
    RewriteCond %{REQUEST_FILENAME}\.php  -f  # but when you put ".php" on the end it is a file that exists
    RewriteRule ^(.+)$ $1\.php [QSA]          # then serve that file (maintaining the query string)
    </IfModule>
    

    奇怪的是,当在windows的XAMPP中尝試此代碼時,此代碼给了我HTTP 500錯誤.删除註釋即可解決.移動註釋也是如此,使它们位於自己的行上,而不是与說明相同。

  • 5月前
    4 #

    尝試以下操作:

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

    參考:

    如何在.htaccess中隱藏.php擴充套件名

  • angularjs:Angular JS:如何繫結到Promise
  • 使用Jersey客戶端上傳大檔案時如何避免OutOfMemoryError