簡體   English   中英

使用apache mod_rewrite創建SEO友好的URL

[英]Creating SEO friendly URLs using apache mod_rewrite

我正在嘗試使用apache mod_rewrite將丑陋的URL轉換為SEO友好URL。

這是我當前的URL的樣子:

index.php?p=search
index.php?p=contact
index.php?p=my-account&user=1
index.php?p=my-account&user=1

這是我對重寫的期望:

mydomain.com/search
mydomain.com/contact
mydomain.com/my-account/1
mydomain.com/my-account/1

如果我通過URL傳遞了一個查詢字符串。 我可以在我的.htaccess文件中執行以下操作。 但不確定在URL查詢字符串多於一個時該怎么做。

# Create SEO friendly URL 
# Eg: index.php?p=search to domain/search
<ifModule mod_rewrite.c>

# Turn on the engine:
RewriteEngine on

# Redirect certain paths to index.php:
RewriteRule ^(search|contact)/?$ index.php?p=$1 

</ifModule>

如果URL有一個字符串,則此方法有效。 誰能告訴我如何針對更多查詢字符串執行此操作。

謝謝。

你可以做:

<ifModule mod_rewrite.c>

# Turn on the engine:
RewriteEngine on

# Redirect certain paths to index.php:
RewriteRule ^(search|contact)/?$ index.php?p=$1 [L,QSA,NC]

RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?p=$1&user=$2 [L,QSA,NC]

</ifModule>

暫無
暫無

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

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