[英]How to check in .htaccess is the subdirectory
我有一個.htaccess文件,在其中我重寫了規則
RewriteRule ^([0-9A-Za-z]+)$ profile.php?username=$1
它使myproject.com/profile.php?username=iamuser
成為myproject.com/iamuser
但是,如果我想轉到一個文件夾(例如“ images”),當我編寫myproject.com/images
,它將以“ images”的身份作為用戶名保留在profile.php上
請幫忙。 謝謝
您應該使用RewriteCond
來檢查請求URI是否屬於任何現有文件/目錄。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9A-Za-z]+)$ profile.php?username=$1 [QSA,L]
-d
測試它是否存在並且是目錄。 -f
測試它是否存在並且是文件。 如果有任何原始請求,則QSA
標志會附加查詢字符串。 L
標志使其成為最后要處理的規則。 如果此規則匹配,則不會處理后面的其他規則。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.