【问题标题】:htaccess rewrite changing urlhtaccess 重写更改 url
【发布时间】:2013-02-22 16:55:19
【问题描述】:

我在连接这些点时遇到了麻烦。是否有中间步骤来更改 .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 的网址

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

我是否遗漏了一些重要的东西,或者我跳过了 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]

【问题讨论】:

    标签: .htaccess rewrite


    【解决方案1】:

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

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

    当存在 URL product.php?id=17&amp;product_name=enchanting%2520pearl 并将其重写为 necklace/17/enchanting%2520pearl 时,将触发此规则。客户端被重定向,浏览器栏应显示新 URL。

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

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

    【讨论】:

    • 嗨奥拉夫感谢您的快速响应。我想我明白你在说什么,但我似乎仍然无法理解。我已经尝试将产品名称更改为 product_name(a-zA-Z...) 并将 id 切换为 id 是数字,我认为这可能是问题所在,但没有。如果这成功了,moniquetrinidadjewelry.com/necklace/id/product_name 的地址实际上应该把我带到原来的正确位置吗?它根本没有影响。我在上面添加了我的整体 ht 访问权限以包含您引用的内容。
    • @HireLogo 我修复了 idproduct_name 并添加了重定向 R 标志。我试着解释这里发生了什么。如果这不是您想要的,请告诉我。
    • 嗨奥拉夫再次感谢...这正是我想要做的,但我没有看到任何事情发生。我已将它包含在我的 .htaccess 中,但没有任何反应。我觉得我在等式中遗漏了一些东西,因为在之前的任何尝试中我还没有看到地址有任何变化。
    猜你喜欢
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多