2016-05-14 113 views
-1

重定向如果url包含特定單詞而不更改它。重定向如果url包含單詞而不更改url使用htaccess

如:http://localhost/APIs/student

應該重定向到「http://localhost/APIs/

我試過很多東西波紋管給他們的一個:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^[A-Z]{10,}\s/+index\.php\?page=([^\s&]+) [NC] 
RewriteRule^/%1? [R=301,L] 
RewriteRule ^([a-z0-9-]+)/?$ /APIs/index.php?page=$1-10 [QSA,L,NC] 

,如果我在通過多個參數上面的代碼中失敗鏈接後斜槓。

+1

提供更多信息。 – hjpotter92

+0

如果我通過「http:// localhost/APIs/student/dd/dd」,它會重定向到404頁面。我想,如果有的話。參數在API中傳遞後,它應該重定向到index.php – Prerna

+0

「.htaccess」文件位於何處? – hjpotter92

回答

0

下面是規則

RewriteEngine on 
RewriteRule ^APIs/(.*)$ APIs/index.php?page=$1 [NC,END] 

如果你請求

http://localhost/APIs/student/test 

你會被內部重定向到(你會看到與上述相同的URL)

http://localhost/APIs/index.php?page=student/test 

index.php文件使用$_GET["page"]得到student/test,你可以決定什麼在此基礎上顯示在頁面中。

+0

不幸的是它不工作Rijul。 – Prerna

+0

創建一個名爲'index.php'的php文件,代碼爲'<?php echo $ _GET [「page」]; ?>並將其放在'http:// localhost/APIs /'目錄並從瀏覽器請求'http:// localhost/APis/student/test'。該頁面應該顯示'學生/測試'。告訴我瀏覽器在說什麼。 –

+0

我已經更新了答案,請檢查它。 –