簡體   English   中英

如何從 url 中隱藏 id 並使其干凈 url 我的 .htaccess 文件目錄是 /home/evidhya/public_html/tutorials/.htaccess

[英]how to hide id from the url and make it clean url my directory of .htaccess file is /home/evidhya/public_html/tutorials/.htaccess

我有以下網址,我想隱藏 id 並使其成為干凈的網址

https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction

干凈的網址應該像下面的網址https://www.evidhya.com/tutorials/AJAX/Introduction

我可以使用下面的 htaccess 代碼來實現。 https://www.evidhya.com/tutorials/569/AJAX/Introduction但我不想在 url 中使用569 id

RewriteEngine On
#RewriteBase /KSTA-Webinar/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#RewriteRule ^(\d+)/?$ tutorials.php?qid=$1/$2/$1/$3 [L,QSA]
RewriteRule ^([\w.-]+)/?$ get_data.php?qid=$1 [L,QSA]
          
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^title=([^/]+)/([^/]+)/([^/]+)/(.+)$
RewriteRule ^tutorials\.php$ /%1/%2/%4? [R=301]

RewriteRule ^tutorials/([\w+%]{2,50})$ /tutorials.php?qid=$1 [QSA,L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ tutorials.php?qid=$1&user=$2&date=$3

RewriteRule ^([^/]+)/([^/]+)/(.+)$ tutorials.php?qid=$1/$2/$1/$3 [L]

好吧,似乎需要 id 來確定結果 url。 我會這樣做:

RewriteEngine on
RewriteRule (\d+)/(\w+)/(\w+) tutorials.php?qid=$1/$2/$3 [L]

並將此規則放在tutorials/.htaccess

當有人訪問https://www.evidhya.com/tutorials/569/AJAX/Introduction 時,它應該加載https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction

暫無
暫無

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

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