簡體   English   中英

從查詢到子目錄HTACCESS中的路徑

[英]from query to path in subdirectory HTACCESS

我在根目錄中安裝了一個帶有WordPress的https域。 在子目錄“ / test /”中,我創建了一個使用GET進行工作的Web應用程序; 路徑是這樣的:

https://www.example.com/test/file.php?url=urlname&etc=etc

我需要將其轉換為:

https://www.example.com/test/urlname/?etc=etc

我還需要從第一種網址重定向到第二種網址。

這是我第一次必須編輯htaccess文件,並且在網上搜索后嘗試了此代碼

RewriteRule ^/?test/([^/]+)/$ test/file.php?url=$1&%{QUERY_STRING} [L,QSA]
RewriteCond %{REQUEST_URI}  ^/test/file\.php$
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^/?test/file\.php$ /test/%1/?%{QUERY_STRING}  [L,R=301]

但顯然不起作用。 有人能幫我嗎?

您可以在DOCUMENT_ROOT/.htaccess文件中使用以下代碼:

RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /test/file\.php\?url=([^\s&]+)(?:&(\S*))?\s [NC]
RewriteRule ^ /test/%1?%2 [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^test/([^/]+)/?$ test/file.php?url=$1 [L,QSA,NC]

暫無
暫無

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

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