0

我在连接这些点时遇到了麻烦。是否有中间步骤来更改 .htaccess 中的 url。这就是我到目前为止所拥有的。moniquetrinidadjewelry.com/necklace/product.php?id=17&product_name=enchanting%2520pearl

和重写

RewriteEngine On
RewriteRule ^$necklace/([a-zA-Z]+)/([0-9]+)/$ product.php?id=$1&product_name=$2

我的目标和我认为如上所述设置的是 moniquetrinidadjewelry.com/necklace/id/product_name 的 url

我不完全确定问题出在哪里。刷新、重新加载或重新开始浏览时,地址栏中没有变化。(即家庭项链>等)

我是否遗漏了一些重要的东西,或者我跳过了 htaccess 本身之外的步骤?

编辑:

# Use PHP5.3 Single php.ini as default
AddHandler application/x-httpd-php53s .php

# Always use www in the domain
# Replace 'moniquetrinidadjewelry' with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?moniuetrinidadjewelry.com$ [NC]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .? http://www.%1moniquetrinidadjewelry.com%{REQUEST_URI} [R=301,L]

RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([0-9]+)&product_name=([a-zA-Z]+)$
RewriteRule product.php necklace/%1/%2/

# For security reasons, Option followsymlinks cannot be overridden.
#Options -MultiViews +FollowSymlinks
Options -MultiViews +SymLinksIfOwnerMatch
RewriteEngine on

# Always use www in the domain
# Replace 'moniquetrinidadjewelry' with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?moniuetrinidadjewelry.com$ [NC]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .? http://www.%1moniquetrinidadjewelry.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

RewriteRule ^/?(.*/?)index\.(htm|html|php) /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 /

<Files error_log>
order allow,deny
deny from all
</Files>

# Ultimate htaccess Blacklist 2 from Perishable Press
# Deny domain access to spammers and other scumbags
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ADSARobot|ah-    ha|almaden|aktuelles|Anarchie|amzn_assoc|ASPSeek|ASSORT|ATHENS|Atomz|attach|attache|autoema    ilspider|BackWeb|Bandit|BatchFTP|bdfetch|big.brother|BlackWidow|bmclient|Boston\     Project|BravoBrian\ SpiderEngine\ MarcoPolo|Bot\     mailto:craftbot@yahoo.com|Buddy|Bullseye|bumblebee|capture|CherryPicker|ChinaClaw|CICC|clip    ping|Collector|Copier|Crescent|Crescent\ Internet\     ToolPak|Custo|cyberalert|DA$|Deweb|diagem|Digger|Digimarc|DIIbot|DISCo|DISCo\     Pump|DISCoFinder|Download\ Demon|Download\     Wonder|Downloader|Drip|DSurf15a|DTS.Agent|EasyDL|eCatch|ecollector|efp@gmx\.net|Email\     Extractor|EirGrabber|email|EmailCollector|EmailSiphon|EmailWolf|Express\     WebPictures|ExtractorPro|EyeNetIE|FavOrg|fastlwspider|Favorites\     Sweeper|Fetch|FEZhead|FileHound|FlashGet\     WebWasher|FlickBot|fluffy|FrontPage|GalaxyBot|Generic|Getleft|GetRight|GetSmart|GetWeb!|Get    WebPage|gigabaz|Girafabot|Go\!Zilla|Go!Zilla|Go-Ahead-    Got-It|GornKer|gotit|Grabber|GrabNet|Grafula|Green\ Research|grub-    client|Harvest|hhjhj@yahoo|hloader|HMView|HomePageSearch|http\     generic|HTTrack|httpdown|httrack|ia_archiver|IBM_Planetwide|Image\ Stripper|Image\     Sucker|imagefetch|IncyWincy|Indy*Library|Indy\     Library|informant|Ingelin|InterGET|Internet\ Ninja|InternetLinkagent|Internet\     Ninja|InternetSeer\.com|Iria|Irvine|JBH*agent|JetCar|JOC|JOC\ Web\     Spider|JustView|KWebGet|Lachesis|larbin|LeechFTP|LexiBot|lftp|libwww|likse|Link|Link*Sleuth    |LINKS\ ARoMATIZED|LinkWalker|LWP|lwp-trivial|Mag-Net|Magnet|Mac\ Finder|Mag-Net|Mass\     Downloader|MCspider|Memo|Microsoft.URL|MIDown\ tool|Mirror|Missigua\     Locator|Mister\     PiX|MMMtoCrawl\/UrlDispatcherLLL|^Mozilla$|Mozilla.*Indy|Mozilla.*NEWT|Mozilla*MSIECrawler|    MS\     FrontPage*|MSFrontPage|MSIECrawler|MSProxy|multithreaddb|nationaldirectory|Navroad|NearSite    |NetAnts|NetCarta|NetMechanic|netprospector|NetResearchServer|NetSpider|Net\     Vampire|NetZIP|NetZip\ Downloader|NetZippy|NEWT|NICErsPRO|Ninja|NPBot|Octopus|Offline\         Explorer|Offline\ Navigator|OpaL|Openfind|OpenTextSiteCrawler|OrangeBot|PageGrabber|Papa\ Foto|PackRat|pavuk|pcBrowser|PersonaPilot|Ping|PingALink|Pockey|Proxy|psbot|PSurf|puf|Pump|        PushSite|QRVA|RealDownload|Reaper|Recorder|ReGet|replacer|RepoMonkey|Robozilla|Rover|RPT-    HTTPClient|Rsync|Scooter|SearchExpress|searchhippo|searchterms\.it|Second\ Street\     Research|Seeker|Shai|Siphon|sitecheck|sitecheck.internetseer.com|SiteSnagger|SlySearch|Smar        tDownload|snagger|Snake|SpaceBison|Spegla|SpiderBot|sproose|SqWorm|Stripper|Sucker|SuperBot    |SuperHTTP|Surfbot|SurfWalker|Szukacz|tAkeOut|tarspider|Teleport\     Pro|Templeton|TrueRobot|TV33_Mercator|UIowaCrawler|UtilMind|URLSpiderPro|URL_Spider_Pro|Vac    uum|vagabondo|vayala|visibilitygap|VoidEYE|vspider|Web\ Downloader|w3mir|Web\ Data\     Extractor|Web\ Image\ Collector|Web\ Sucker|Wweb|WebAuto|WebBandit|web\.by    \.mail|Webclipping|webcollage|webcollector|WebCopier|webcraft@bea|webdevil|webdownloader|We    bdup|WebEMailExtrac|WebFetch|WebGo\     IS|WebHook|Webinator|WebLeacher|WEBMASTERS|WebMiner|WebMirror|webmole|WebReaper|WebSauger|W    ebsite|Website\ eXtractor|Website\     Quester|WebSnake|Webster|WebStripper|websucker|webvac|webwalk|webweasel|WebWhacker|WebZIP|W    get|Whacker|whizbang|WhosTalking|Widow|WISEbot|WWWOFFLE|x-Tractor|^Xaldon\     WebSpider|WUMPUS|Xenu|XGET|Zeus.*Webster|Zeus [NC]
RewriteRule ^.* - [F,L]
4

1 回答 1

0

如果我理解正确,您必须首先在 a 中捕获查询字符串部分,RewriteCond然后在 a 中使用它RewriteRule

RewriteCond %{QUERY_STRING} ^id=([0-9]+)&product_name=([a-zA-Z]+)$
RewriteRule product.php necklace/%1/%2/ [R,L]

当有 URLproduct.php?id=17&product_name=enchanting%2520pearl并将其重写为necklace/17/enchanting%2520pearl. 客户端被重定向,浏览器栏应显示新 URL。

如果你想反过来,这个应该可以

RewriteRule necklace/([0-9]+)/([a-zA-Z]+) product.php?id=$1&product_name=$2
于 2013-02-22T17:29:04.443 回答