簡體   English   中英

如何使用.htaccess將所有url重寫為index.php

[英]How to rewrite all url's to index.php with .htaccess

在一個應用程序中,我希望所有用戶都從index.php開始。 所以我想將所有直接URL重定向到其他頁面到此文件。

當我使用以下語法時,只重寫不存在的文件,但我也想重定向現有的URL。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f表示:如果此文件不存在,請應用RewriteRule。

RewriteCond %{REQUEST_FILENAME} !-d表示:如果此目錄不存在,請應用RewriteRule。

采用:

RewriteEngine on
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]

編輯:

如果您只想在URL尚未以/index.php開頭時/index.php ,請使用以下額外條件:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /index.php/?path=$1 [NC,L,QSA]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM