Improved SEO with mod_rewrite

PHP Advanced and Object-Oriented Programming Third Edition

  1 <?php
  2 //D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess\mod_rewrite.php
  3
  4 echo ‘?w=‘.$_GET[‘w‘].‘&wb=‘.$_GET[‘wb‘];
  5
  6 /*
  7 http://localhost/0613pm/w_wwwroot/n/test_htaccess/mod_rewrite.php?w=‘cheer‘&wb=‘time‘
  8 http://localhost/0613pm/w_wwwroot/n/test_htaccess/mod_rewrite.php?w=%27cheer%27&wb=%27time%27
  9 ?w=‘cheer‘&wb=‘time‘
 10 */
 11
 12 /*
 13 http://localhost/0613pm/w_wwwroot/n/test_htaccess/mod_rewrite.php?w=cheer&wb=time
 14 ?w=cheer&wb=time
 15 */
 16
 17 /*
 18 D:\wamp64\bin\apache\apache2.4.18\conf
 19
 20 #
 21 # Deny access to the entirety of your server‘s filesystem. You must
 22 # explicitly permit access to web content directories in other
 23 # <Directory> blocks below.
 24 #
 25 <Directory />
 26     AllowOverride none
 27     Require all denied
 28 </Directory>
 29
 30
 31 */
 32
 33 /*
 34 D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess
 35 新建 .htaccess
 36
 37 #2016/8/13-11:11
 38 <IfModule mod_rewrite.c>
 39 #the .htaccess file mustfirst check for the module and turn on the rewrite engine:
 40 RewriteEngine on
 41 #After enabling the engine, and before the closing IfModule tag, you add rules dictating the rewrites.
 42 #The syntax is RewriteRule match rewrite
 43 RewriteRule w.php dearchild.php
 44 RewriteRule ^rewrite_ok/\wzero/\wfirst$ mod_write.php?w=$1&wb=$2
 45 </IfModule>
 46
 47
 48 apache无法启动-0
 49 #2016/8/13-11:04
 50 <Directory ‘D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess‘ />
 51 AllowOverride All
 52 <Directory>
 53 apache无法启动-1
 54 #2016/8/13-11:04
 55 <Directory ‘D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess‘ />
 56 AllowOverride All
 57 </Directory>
 58 apache无法启动-2
 59 #2016/8/13-11:04
 60 <Directory "D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess" />
 61 AllowOverride All
 62 <Directory>
 63 apache启动
 64 #2016/8/13-11:04
 65 <Directory "D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess">
 66 AllowOverride All
 67 <Directory>
 68 TOOLS- Check http.conf syntax  逐步排错
 69
 70 */
 71
 72 /*
 73 D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess\w.php
 74 任意
 75 D:\wamp64\www\0613pm\w_wwwroot\n\test_htaccess\dearchild.php
 76 <?php
 77 echo ‘dear_child_w‘;
 78 http://localhost/0613pm/w_wwwroot/n/test_htaccess/w.php
 79
 80 */
 81 echo ‘dear_child_w‘;//dear_child_w
 82 //验证通过
 83 /*
 84 RewriteRule somepage.php otherpage.php
 85 With that code, any time a user goes to somepage.php, the user will be shown the contents ofotherpage.php, although the browser will still display somepage.php in the address bar.
 86 To be clear, that’s not actually a good use of mod_rewrite, as a literal redirection could beaccomplished with the less complex mod_alias module instead. However, a line like that doesrepresent an easy way to test that mod_rewrite is working.
 87 */
 88
 89 /*
 90 http://localhost/0613pm/w_wwwroot/n/test_htaccess/mod_write.php?w=wchild&wb=wchildb
 91 Not Found
 92
 93 The requested URL /0613pm/w_wwwroot/n/test_htaccess/mod_write.php was not found on this server.
 94
 95 Apache/2.4.18 (Win64) PHP/5.6.19 Server at localhost Port 80
 96
 97 */
 98
 99 /*
100 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/wzero/wfirst
101 Not Found
102
103 The requested URL /0613pm/w_wwwroot/n/test_htaccess/mod_write.php was not found on this server.
104
105 Apache/2.4.18 (Win64) PHP/5.6.19 Server at localhost Port 80
106
107 #2016/8/13-11:44
108 <IfModule mod_rewrite.c>
109 #the .htaccess file mustfirst check for the module and turn on the rewrite engine:
110 RewriteEngine on
111 #After enabling the engine, and before the closing IfModule tag, you add rules dictating the rewrites.
112 #The syntax is RewriteRule match rewrite
113 RewriteRule w.php dearchild.php
114 RewriteRule ^rewrite_ok/\wzero/\wfirst$ mod_rwrite.php?w=$1&wb=$2
115 </IfModule>
116
117 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/wzero/wfirst
118
119 ?w=&wb=
120 //get空,继续修正
121 */
122
123 /*
124 #2016/8/13-11:57
125 <IfModule mod_rewrite.c>
126 RewriteEngine on
127 RewriteRule w.php dearchild.php
128 RewriteRule ^rewrite_ok/\w{1,}/\w{1,}$  mod_rewrite.php?w=$1&wb=$2
129 </IfModule>
130
131 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/sd
132 //?w=&wb=
133
134
135 #2016/8/13-11:58
136 <IfModule mod_rewrite.c>
137 RewriteEngine on
138 RewriteRule w.php dearchild.php
139 RewriteRule ^rewrite_ok/(\w{1,})/(\w{1,})$  mod_rewrite.php?w=$1&wb=$2
140 </IfModule>
141
142 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/sd
143 //?w=2er32&wb=sd
144
145 进一步研究-0
146 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32
147 //Not Found
148
149 The requested URL /0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32 was not found on this server.
150
151 Apache/2.4.18 (Win64) PHP/5.6.19 Server at localhost Port 80
152
153 进一步研究-1
154 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/t/
155 //Not Found
156
157 The requested URL /0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/t/ was not found on this server.
158
159 Apache/2.4.18 (Win64) PHP/5.6.19 Server at localhost Port 80
160
161 考虑用户习惯,优化正则,
162
163 #2016/8/13-12:05
164 <IfModule mod_rewrite.c>
165 RewriteEngine on
166 RewriteRule w.php dearchild.php
167 RewriteRule ^rewrite_ok/(\w{1,})/(\w{1,})/{0,}$  mod_rewrite.php?w=$1&wb=$2
168 </IfModule>
169
170 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/t/
171 //?w=2er32&wb=t
172
173 a-beautiful-world
174
175 #2016/8/13-12:07
176 <IfModule mod_rewrite.c>
177 RewriteEngine on
178 #The syntax is RewriteRule match rewrite
179 RewriteRule w.php dearchild.php
180 RewriteRule ^rewrite_ok/(\w{1,})/(\w{1,})/{0,}/a-beautiful-world$  mod_rewrite.php?w=$1&wb=$2
181 </IfModule>
182 */
183 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/ta-beautiful-world
184 //Not Found
185
186 The requested URL /0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/ta-beautiful-world was not found on this server.
187
188 Apache/2.4.18 (Win64) PHP/5.6.19 Server at localhost Port 80
189
190 http://localhost/0613pm/w_wwwroot/n/test_htaccess/rewrite_ok/2er32/t/a-beautiful-world
191 //?w=2er32&wb=t

//Search Engine Optimization

The modularized site as written has a number of benefits, starting with the fact that it will be easier to maintain and expand as needed.

//模块化站点 维护 扩展

mod_rewrite is a tool that lets you instruct the server that when the user goes to one URL, the server should provide another resource.

mod_rewrite makes use of regular expressions, so the matching pattern and resulting actual URL can be as complex as needed.

Two ways to change Apache‘s behavior

0-edit the primary Apache configuration file

1-create directory-specific files

// 全局配置文件 目录相关文件

The primary configuration file is httpd.conf, found within a conf directory, and it dictates how the entire Apache Web server runs(where the httpd.conf file is on your system will depend on many things). An .htaccess file(pronounced “H-T access”) is placed within a Web directory and is used to affect how Apache behaveswithin just that folder and subfolders.Generally speaking, it’s preferable to make changes in the httpd.conf file, since this file needs to be read only by the Web server each time the server is started. Conversely, .htaccess files must be readby the Web server once for every request to which an .htaccess file might apply. For example, if youhave www.example.com/somedir/.htaccess, any request to www.example.com/somedir/whatever requires reading the .htaccess file, as well as reading an .htaccess file that might exist in www.example.com/. On the other hand, in shared hosting environments, individual users are not allowed to customize the entire Apache configuration, but they may be allowed to use .htaccess to make changes that only affect their sites. And changes to the primary configuration file do require restarting Apache to take effect.

发问:

0-references to external resources cheated the browser! Much more we can do!

时间: 2024-10-29 19:05:33

Improved SEO with mod_rewrite的相关文章

ASP.NET的SEO:正则表达式

目前国内主流的网站内容管理系统中,有大部分是可以将动态的PHP.ASP.ASPX等文档直接生成HTML的.但是由于有些网站的内容较多,因此如果单纯的采取直接生成的方式,将会占用大量的服务器资源.在这种情况下,我们就可以使用"伪静态"的方式,对网站URL静态化,以达到SEO的目的. 伪静态所需要的工具 如果网站使用的是独立服务器的话,那么我们就可以随意的对网站进行伪静态操作了,假如网站使用的服务器是Apache服务器,那么它自带了mod_rewrite来实现URL的重写功能(URL Re

使用Prerender.io为angular项目做SEO

现在的项目的为了更好的分工明确,降低耦合都开始采用前后端分离的形式进式开发,我们也采用这种开发形式,前端用angular开发.虽说刚开始也遇各种坑,但是后期熟悉了之后简直爽呆.一个比较大的坑就是SEO问题,前后端分离页面的路由一般都是放在前端的,用hashBang的方式控制路由.但是这会出现一种情况页面无法被搜索引擎抓取,这对于SEO简直就是灾难. 有问题就有解决办法,一般的做法就是在服务器加一个可以渲染出静态页面的中间件,类似于phantomjs,zimbile.js,只要发现是搜索引擎的蜘蛛

SEO基础知识_绝密教程

<p align="center"> </p> <p>   </p> <p align="center"> 第一次接触SEO,请阅读本基础指南入门,也可以注册论坛:<a  1-1.html" target="_blank"><span style="color:black;">从一句话入门</span><span s

thinkphp之url的seo优化

1.网站url做seo优化的原因 SEO是由英文Search Engine Optimization缩写而来, 中文意译为"搜索引擎优化".SEO是指通过对网站进行站内优化(网站结构调整.网站内容建设.网站代码优化等)和站外优化,从而提高网站的关键词排名以及公司产品的曝光度. URL优化的效果跟站点在百度的权重关联性不大,但是对收录.蜘蛛爬行和传递权重有明显的提升. 蜘蛛爬行原理:蜘蛛爬行原理有 深度优先和宽度优先了解: (1)深度优先:深度优先适用于一些大站,蜘蛛很渴望得到他的内容,

SEO工具箱:PHP自动生成PHPCMS伪静态规则.htaccess

这个做SEO的时候非常需要,以前从DEDECMS转战PHPCMS,最痛苦的就是设置伪静态,一直想设置 栏目名/文章ID.html 这样的规则,但是显然PHPCMS默认不提供,只提供最原始的 list-1-1.html ,show-1-1.html,这种URL对搜索引擎和用户都是不友好的(不符合百度搜索引擎指南中对URL友好的描述),哈哈,或者只是自己纠结. 如果非要以前非要这么设置的话,就得一条条手工加,没想到居然有一天自己也能破这个问题(其实只是个简单的读数据库的问题). 第一步:PHPCMS

CodeIgniter Apache服务器 htaccess SEO重写写法

1)支持重写 2)兼容所有APACHE 服务器 3)如果不是文件,请求的结尾不包括反斜杠,自动跳转到反斜杠 4)文件名 .htaccess 5)这个放到nginx服务器怎么都不支持重写,如果有知道的人,告诉我一下,特别感谢 default7#zbphp.com. <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ Rewr

301重定向方法大全及SEO中网址规范化,看着不错先收下

301重定向方法大全及SEO中网址规范化 现在大多数网站都存在一些内容相同但网址(URL)不一样的重复内容,这些重复的内容对于搜索引擎来说却可能被认为是复制网页,复制网页虽然不会被惩罚但因多个网址存在分散了页面权重,肯定不利于其排名.解决这个问题就需要网址规则化处理,网址规范化(URL canonicalization)从字面上理解就是搜索引擎挑选最好的URL网址作为真正网址的过程,通过网址规范化处理把最好的URL网址反馈给搜索引擎. 解决网址规范化问题有好多方法,目前我们讲使用301重定向来进

SEO学习步骤总结入门教程

在这里,简单的把SEO的学习步骤说了一下,今天我们一起来把SEO学习步骤每一步的主要内容拿出来重点强调一下并做个总结.  定位好网站内容以后把你所想做排名的关键词定位好,关键词里包括了主关键词和长尾关键词.这里重点强调了不可以忽略长尾关键词的作用.  对于一个好的网站结构可以让搜索引擎蜘蛛顺利的抓取我网站的内容,进而达到被收录的目的.比较有利于蜘蛛抓取的网站结构,一般来说,收录数量相对来说会比较多.,只有让搜索引擎收录你网站页面那搜索引擎才会释放出来,这样网站关键词才可能有排名.  这里重点要注

了解搜索引擎来进行SEO

搜索引擎的工作的过程非常复杂,而简单的讲搜索引擎的工过程大体可以分成三个阶段.爬行和抓取:搜索引擎蜘蛛通过跟踪链接访问页面,获取页面HTML代码存入数据库.预处理:搜索赢球对抓取来的页面数据文字进行文字提取.中文分词.索引等处理,以备排名程序调用.排名:用户输入关键字后,排名调用索引库数据,计算相关性,然后按一定格式生成搜索结果页面. 爬行和抓取 爬行和抓取是搜索引擎工作的第一步,完成数据收集任务. 蜘蛛 搜索引擎用来爬行和访问页面的程序被称为蜘蛛(spider),也称为机器人(bot). 蜘蛛