簡體   English   中英

在htaccess中為用戶配置文件創建重寫規則

[英]Create Rewrite rule in htaccess for a user profile

所以我有一個難題。

無法弄清楚如何將此URL重寫為此URL:

URL = www.EXAMPLE.com / users / USERNAME

此URL = www.EXAMPLE.com/USERNAME

這不是我第一次使用Stack Overflow,但這是我第一次真正需要一個帳戶來找到我的答案。 我將相應地感謝。

謝謝,尼克

編輯:

    RewriteRule ^user/(.*)$ /$1 [R=301,L]

但是我說,我得到一個404頁。

該頁面成功重定向,但改用404。

HTACCESS如下:

   ## Mod_rewrite in use.

   RewriteEngine On
   RewriteRule ^user/(.*)$ /$1 [R=301,L]

   ## Begin - Rewrite rules to block out some common exploits.
   # If you experience problems on your site block out the operations listed below
   # This attempts to block the most common type of exploit `attempts` to Joomla!
   #
   # Block out any script trying to base64_encode data within the URL.
   RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
   # Block out any script that includes a <script> tag in URL.
   RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
   # Block out any script trying to set a PHP GLOBALS variable via URL.
   RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
   # Block out any script trying to modify a _REQUEST variable via URL.
   RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
   # Return 403 Forbidden header and show the content of the root homepage
   RewriteRule .* index.php [F]
   #
   ## End - Rewrite rules to block out some common exploits.

   ## Begin - Custom redirects
   #
   # If you need to redirect some pages, or set a canonical non-www to
   # www redirect (or vice versa), place that code here. Ensure those
   # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
   #

   ## End - Custom redirects

   ##
   # Uncomment following line if your webserver's URL
   # is not directly related to physical file paths.
   # Update Your Joomla! Directory (just / for root).
   ##

   # RewriteBase /

   ## Begin - Joomla! core SEF Section.
   #
   RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
   #
   # If the requested path and file is not /index.php and the request
   # has not already been internally rewritten to the index.php script
   RewriteCond %{REQUEST_URI} !^/index\.php
   # and the request is for something within the component folder,
   # or for the site root, or for an extensionless URL, or the
   # requested URL ends with one of the listed extensions
   RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
   # and the requested path and file doesn't directly match a physical file
   RewriteCond %{REQUEST_FILENAME} !-f
   # and the requested path and file doesn't directly match a physical folder
   RewriteCond %{REQUEST_FILENAME} !-d
   # internally rewrite the request to the index.php script
   RewriteRule .* index.php [L]
   #
   ## End - Joomla! core SEF Section.

[13年4月8日更新]因此,一段時間后,我發現我使用的擴展的唯一方法是與Joomla一起使用! 您需要使用名為sh404sef的單獨擴展名才能完成此工作。 因此,簡而言之,無需像我想的那樣編輯HTACCESS文件。 最終花了40美元,它立即起作用。 哈哈

我發現對.htaccess網址重寫有用的站點是: http : //roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

這個例子:

將yoursite.com/user.php?username=xyz重寫為yoursite.com/xyz

您是否已檢查zorpia.com。如果在瀏覽器中鍵入http://zorpia.com/roshanbh233 ,則可以在那看到我的個人資料。 如果要進行相同類型的重定向,即從http://yoursite.com/xyzhttp://yoursite.com/user.php?username=xyz,則可以將以下代碼添加到.htaccess文件中。

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

因此,在您的情況下,您可以尋求:

RewriteRule ^users/([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^users/([a-zA-Z0-9_-]+)/$ user.php?username=$1

這應該回答你的問題

RewriteRule ^users/(.*)$ $1

來源: .htaccess從子目錄重寫到根目錄

參見https://stackoverflow.com/questions/20610980/mod-rewrite-redirect-except-parked-domain所有www.primary.com都訪問www.primary.com/webtrees

Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond $1 !^parked.com/
RewriteCond $1 !^piwik/
RewriteCond $1 !^wordpress/
RewriteCond $1 !^marker.htm
RewriteCond %{REQUEST_URI} !^/webtrees/
RewriteRule ^(.*)$ /webtrees/$1 [L]

暫無
暫無

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

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