Cách ẩn mọi thứ sau tên trang web của bạn bằng .htaccess (How to hide everything after your webpage name with .htaccess)


問題描述

Cách ẩn mọi thứ sau tên trang web của bạn bằng .htaccess (How to hide everything after your webpage name with .htaccess)

When I enter my site and when I browse other sites, I get a parameter more: etc .php?p=pagename&id=1 

I would like to hide everything after .dk

I have tried:

RewriteEngine On
RewriteRule ^([a‑zA‑Z0‑9]+)$ index.php?p=$1 [L,QSA]
RewriteRule ^([a‑zA‑Z0‑9]+)/$ index.php?p=$1 [L,QSA]

RewriteRule ^/index.php$ http://www.madsweb.dk/ [R,NC,L]

But it doesn't seem to work.

Can anyone help me out?


參考解法

方法 1:

  

RewriteRule ^/index.php$ http://www.madsweb.dk/ [R,NC,L]

Rewrites work the other way around. You don't rewrite what the user sees in his address bar but you rewrite a request to another request (like a redirect, but handled transparently on the server).

That's also the reason that what you try to do there is not possible.

You could use a frame instead if you like the 90s and don't care about usability.

But jokes aside, it's the best to build upon this rule, which is already good:

  

RewriteRule ^([a‑zA‑Z0‑9]+)$ index.php?p=$1 [L,QSA]

and get the additional information (id in this case) into the pattern. Example:

RewriteRule ^([a‑zA‑Z0‑9]+)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^([a‑zA‑Z0‑9]+)/([0‑9]+)$ index.php?p=$1&id=$2 [L,QSA]

or more general (but still only one parameter):

RewriteRule ^([a‑zA‑Z0‑9]+)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^([a‑zA‑Z0‑9]+)/([a‑zA‑Z0‑9]+)/([0‑9]+)$ index.php?p=$1&$2=$3 [L,QSA]

方法 2:

  

I would like to hide everything after .dk

This is impossible. mod_rewrite cannot remove the need to have unique URLs for each resource.

(And if you did manage to do it, then it would break linking, including bookmarking and search engines).

(by Mads AndersenFabian SchmenglerQuentin)

參考文件

  1. How to hide everything after your webpage name with .htaccess (CC BY‑SA 3.0/4.0)

#url #.htaccess #PHP #mod-rewrite #get






相關問題

正則表達式查找和替換 url 不起作用或如何使其起作用 (Regex to Find and Replace url does not work or how to make it work)

子網站的 URL 重寫? (URL Rewriting for a Subsite?)

使用 htaccess 從基本 URL 中刪除變量 (Remove variable from base URL with htaccess)

在 URL 地址中使用項目名稱而不是 ID (Using item's name in the URL address instead of IDs)

Perl Chèn chuỗi vào url tại các địa điểm cụ thể (Perl Inserting string into a url at specific places)

Cách ẩn mọi thứ sau tên trang web của bạn bằng .htaccess (How to hide everything after your webpage name with .htaccess)

在 gwt 框架中使用參數更改 url (Changing url with parameters in gwt framework)

用於 SEO 目的的 Nodejs URL 修改 (Nodejs URL modifications for SEO purposes)

將用戶重定向到外部站點 (Redirecting user to external site)

Python 循環遍歷 csv 文件中的 url 返回 \ufeffhttps:// (Python Looping through urls in csv file returns \ufeffhttps://)

主頁中的 React Router 目標 div id (React Router target div id in home page)

.htaccess https、www 和子域靜默重寫 (.htaccess https, www and subdomain silent rewrite)







留言討論