![](/img/trans.png)
[英]How can I use the .htaccess file to rewrite URL's for a subdirectory?
[英]How to use .htaccess to rewrite URL's with @username
我在 PHP 中有一個配置文件系統。 如果你想訪問他們的個人資料,你必須轉到 /profile.php?user=username 我希望能夠重寫這個 /@username。
目前,我的 .htaccess 代碼是這樣的:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ - [F]
RewriteRule ^@(.*)$ profile.php?user=$1 [L,QSA]
已修復:我必須在 apache 配置中將 AllowOverride 更改為 All。
<Directory /path/to/directory>
AllowOverride All
</Directory>
並將我的 htaccess 文件更改為:(感謝回答此問題的人)
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^@(.*)/?$ profile.php?user=$1 [L]
根據您顯示的示例,您能否嘗試以下操作。 Where considering that you are hitting URL like http://localhost:80/@test"
which you want it to be served by http://localhost:80/profile.php?user=$1
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^@(.*)/?$ profile.php?user=$1 [L]
同樣正如評論中提到的,你不想使用你的[F]
規則顯示的示例 htaccess 所以我已經從這里刪除了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.