我有一個舊系統,想縮短 URL。
眼下:
www.site.com/app/views/accessories.php
我想這樣打開它:
www.site.com/accessories.php
我試著這樣做:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteRule ^(.*)$ app/Views/$1 [NC,QSA]
但是這個錯誤出現“內部服務器錯誤”。怎么了?
我的檔案夾結構如下:

如您所見,檔案不在根目錄中。它們位于兩個app/views/檔案夾中。
因此,頁面打開時鏈接又大又丑。
www.site.com/app/views/acessorios.php
www.site.com/app/views/clientes.php
www.site.com/app/views/empresas.php
我希望我能像這樣打開它們:
www.site.com/acessorios.php OR www.site.com/acessorios
www.site.com/clientes.php OR www.site.com/clientes
www.site.com/empresas.php OR www.site.com/empresas
也就是說,看起來不像app/views/在網址中。
uj5u.com熱心網友回復:
第一個解決方案:使用您顯示的示例和嘗試,請嘗試遵循 .htaccess 規則檔案。確保將您的 .htaccess 規則檔案與您的應用程式檔案夾一起放置(不是在其中,而是在它旁邊)。還要確保在測驗 URL 之前清除瀏覽器快取。
RewriteEngine ON
RewriteBase /app/views/
##External redirect rules from here.
RewriteCond %{THE_REQUEST} \s/app/views/([^.]*\.php)\s [NC]
RewriteRule ^ /%1? [R=301,L]
##Internal rewrite rules from here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]*\.php)/?$ /app/views/$1 [QSA,L]
第二種解決方案:將 URL 重定向到www.site.com/acessorios的規則如下:
RewriteEngine ON
RewriteBase /app/views/
##External redirect rules from here.
RewriteCond %{THE_REQUEST} \s/app/views/([^.]*)\.php\s [NC]
RewriteRule ^ /%1? [R=301,L]
##Internal rewrite rules from here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ /app/views/$1.php [QSA,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/517021.html
