久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何像stackoverflow一樣重寫SEO友好的url

How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一樣重寫SEO友好的url)
本文介紹了如何像stackoverflow一樣重寫SEO友好的url的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果您訪問如下網址:http://stackoverflow.com/questions/9155602/ 地址欄將更新為 http://stackoverflow.com/問題/9155602/redirect-existing-file-to-different-url-using-mod-rewrite.這不是用 JavaScript 完成的,也不是用硬刷新完成的,我最好的猜測是它是用 mod_rewrite 完成的;但是,如果沒有服務器端用php處理,它怎么知道文章的標題?

If you go to a url like the following: http://stackoverflow.com/questions/9155602/ the address bar will be updated to http://stackoverflow.com/questions/9155602/redirect-existing-file-to-different-url-using-mod-rewrite. This is not done with JavaScript and not with a hard-refresh, my best guess is that it's done with mod_rewrite; however, how would it know the title of the article without server side processing with php?

我剛剛更新了我的網站以使用 SEO 友好的 url,以前是 /shows.php?id=review-1,現在是 /review/1/super-baseball-2020.當涉及到我的重寫時,最后的文本實際上并不重要,即:

I just updated my site to use SEO friendly url's, it used to be /shows.php?id=review-1 and now it's /review/1/super-baseball-2020. The text at the end doesn't actually really matter when it comes to my rewrite which is:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)/([0-9]+)/([a-z0-9-]+)?/?$ /shows.php?id=$1-$2 [L,NC]

我目前確保 Google 不會因為重復內容而向我發送信息,并且書簽得到正確轉發的方法如下:

My current path of making sure Google doesn't hit me for duplicate content, and that bookmarks get forwarded properly is the following:

RewriteCond %{THE_REQUEST} ^GETs/shows.php?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-1(?:&|$) [NC]
RewriteRule ^ /review/1/super-baseball-2020/? [R=301,L,NC]
RewriteCond %{THE_REQUEST} ^GETs/shows.php?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-2(?:&|$) [NC]
RewriteRule ^ /review/2/aero-fighters-2/? [R=301,L,NC]
RewriteCond %{THE_REQUEST} ^GETs/shows.php?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-3(?:&|$) [NC]
RewriteRule ^ /review/3/aero-fighters-3/? [R=301,L,NC]
.... and so on ....

該解決方案非常短視,需要在我的 .htaccess 中放入數千行.

That solution is very shortsighted and is thousands of lines to put into my .htaccess.

推薦答案

沒有服務器端怎么知道文章標題用php處理?

how would it know the title of the article without server side processing with php?

mod_rewrite 只能做這么多.另外,你必須更新太多.最好使用腳本處理這些請求.創建一個 .htaccess,類似于你所做的:

mod_rewrite can only do so much. Plus, you'd have to update it too much. It's best to handle these requests with scripting. Create an .htaccess, similar to what you've done:

<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]
</IfModule>

然后在您的 index.php 中,拆分 REQUEST_URI 以解析出 /review/1/,在數據庫中查找id 為 1 的評論標題,將其傳遞給您的友好 URI (slug) 函數,并將其附加到 url,然后重定向.

Then in your index.php, split the REQUEST_URI to parse out the /review/1/, look in the database for the title of the review with id of 1, pass it to your friendly URI (slug) function, and append it to the url, then redirect.

這篇關于如何像stackoverflow一樣重寫SEO友好的url的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 中文字幕 在线观看 | 久久毛片| 精品免费国产视频 | 欧美视频三区 | 天天躁日日躁狠狠躁2018小说 | 亚洲导航深夜福利涩涩屋 | 亚洲一区亚洲二区 | 欧美在线视频免费 | 久草电影网 | 91精品国产91久久久久久最新 | 日本特黄a级高清免费大片 特黄色一级毛片 | 91网站在线看 | 亚洲一区二区精品视频 | 亚洲欧洲一区二区 | 国产探花在线精品一区二区 | 四虎在线观看 | 国产精品久久久久久久久久久久久久 | 免费在线一区二区 | 欧美一级特黄aaa大片在线观看 | 亚洲天堂免费在线 | 国产精品久久久久婷婷二区次 | 欧美精品一区二区三区在线四季 | 久久精品中文 | 久久91| 国产高清精品一区二区三区 | 欧美一级免费看 | 久久成人免费视频 | 在线观看午夜视频 | 日韩理论电影在线观看 | 国产成人在线一区二区 | 精品久久久久久久人人人人传媒 | 亚洲国产视频一区二区 | www.欧美| 成人一区二区三区 | 一区二区在线不卡 | 国产成人综合在线 | 亚洲成人一区二区在线 | 国产精品91视频 | 日韩精品一区二区三区视频播放 | 免费在线观看毛片 | 中文字幕视频在线 |