簡體   English   中英

.htaccess RewriteRule自動網址

[英].htaccess RewriteRule Automatically URL

好吧,我在.htaccess上獲得了此代碼

RewriteRule page/(.*) ?page=$1
RewriteRule search/(.*) search.php?search=$1
RewriteRule post/(.*) post.php?id_post=$1

它有效,但我需要手動更改網址。

而且我有很多頁面可以更改它。

還有其他方法可以將代碼放在.htaccess中,並使瀏覽器自動獲取正確的url嗎?

例:

http://example.com/post.php?id_post=1

http://example.com/post/1

# Redirect old Page URLs to new URLs
# Old URL format: http://example.com/?page=pagename
# New URL format: http://example.com/page/pagename
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^(.*)$ page/%1? [R=301,L]

# Redirect old Search URLs to new URLs
# Old URL format: http://example.com/search.php?search=keyword
# New URL format: http://example.com/search/keyword
RewriteCond %{REQUEST_URI} search.php
RewriteCond %{QUERY_STRING} ^search=(.*)$
RewriteRule ^(.*)$ search/%1? [R=301,L]

# Redirect old Post URLs to new URLs
# Old URL format: http://example.com/post.php?id_post=1
# New URL format: http://example.com/post/1
RewriteCond %{REQUEST_URI} post.php
RewriteCond %{QUERY_STRING} ^id_post=([0-9]*)$
RewriteRule ^(.*)$ post/%1? [R=301,L]

# ** Any requests with an old URL should have been processed before this comment,
# ** and any requests with a new URL should only be processed by these rules:

# Support new SEO-friendly URLs
RewriteRule page/(.*) index.php?page=$1
RewriteRule search/(.*) search.php?search=$1
RewriteRule post/(.*) post.php?id_post=$1

暫無
暫無

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

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