当前位置:网站首页>Get you started with Apache pseudo static configuration

Get you started with Apache pseudo static configuration

2022-07-05 13:10:00 InfoQ

Preface

Website pseudo static
, Mainly to increase the friendliness of search engines , It is convenient for website content to be included by search engines . Similar to those commonly used on websites 301 Redirect 、404 The setting of the page is waiting SEO Aspects are essential .
Pseudo static is relative to real static , Usually we want to enhance the friendliness of search engines , All the content of the article will be generated into a static page , But some friends in order to display some information in real time . Or I want to use dynamic script to solve some problems . Can't use static way to show website content . But this has lost the friendly side to search engine .

What are the benefits of pseudo static websites ?
  1、 In the early stage of the website, if the website is pseudo static , It is more conducive to search engine collection , Dynamic ones are not easy to include .
  2、 Pseudo static for SEO Is of great significance , The storage capacity of real static page space is large , Delete or update these html Files can cause a large number of file fragments , Destroy the bad track of the disk , And pseudo static can better alleviate the pressure of the server , Enhance the collection of pages by search engines ; Although dynamic pages can be updated in real time , But sometimes it will lead to a dead cycle , Not friendly to search engines , But pseudo static doesn't happen .
   But with the continuous updating of search engine technology , Gradually, search engines are beginning to recognize dynamic pages , Here is Baidu optimization Official Guide 2.0 Which clearly indicates the static page ULR Perfection can increase the user experience , Dynamic pages can still be included , as long as URL Just don't have too many parameters .

modify Apache To configure

open apache Configuration file for httpd.conf
find
#LoadModule rewrite_module modules/mod_rewrite.so
Put the front # Get rid of . Add if not , But you have to choose one line , send apache Support  mod_rewrite  modular
Find the following code in the configuration file :
<Directory &quot;D:/ApacheServer/web&quot;>
 #
 # Possible values for the Options directive are &quot;None&quot;, &quot;All&quot;,
 # or any combination of:
 # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
 #
 # Note that &quot;MultiViews&quot; must be named *explicitly* --- &quot;Options All&quot;
 # doesn't give it to you.
 #
 # The Options directive is both complicated and important. Please see
 # http://httpd.apache.org/docs/2.2/mod/core.html#options
 # for more information.
 #
 
 Options Indexes FollowSymLinks

 #
 # AllowOverride controls what directives may be placed in .htaccess files.
 # It can be &quot;All&quot;, &quot;None&quot;, or any combination of the keywords:
 # Options FileInfo AuthConfig Limit
 #

 AllowOverride None

 #
 # Controls who can get stuff from this server.
 #

 Order allow,deny
 Allow from all
</Directory>

hold
AllowOverride None  Switch to  AllowOverride All  send apache Support  .htaccess  file
then , restart apache The server
When you want to enable pseudo static  PHP  Create a project under the root directory  .htaccess  file

stay  .htaccess  Input content in the file
<IfModule mod_rewrite.c>

 RewriteEngine on

 RewriteRule index.html$ index.php

 RewriteRule index-([1-9]+[0-9]*).html$ index.php?p=$1

 RewriteRule ([a-z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2

</IfModule>

notes :
RewriteEngine  For rewriting engine switches ,on For opening ,off To close .
RewriteRule  It's the routing rule , The previous path is the path to be entered in the browser , Here we can use regular expressions . The previous path is the path to be entered in the browser , Here we can use regular expressions .+ Space   The back path is the actual turning path of the background ,

Parameters can be transferred when turning to the actual path in the background , The background page in the example can use GET[′p′]GET[′p′]_GET[‘action’] GET[‘id′] To receive GET[‘id′] To receive 1  Represents the value of the first regular expression entered in the browser path , And so on ,$2 Represents the value of the second regular expression

RewriteRule  Regular expressions in routing rules are in parentheses  ()  Cover up
The project of the example is test
Under the project  index.php  Content written in the page

<?php
if ($_GET ['p']) {
 echo &quot;p : &quot; . $_GET ['p'];
}

if ($_GET ['action']) {
 echo &quot;action : &quot; . $_GET ['action'];
}

if ($_GET ['id']) {
 echo &quot;id : &quot; . $_GET ['id'];
}
?>

Enter... In the browser
http://localhost/test/index.html
http://localhost/test/index-99.html
http://localhost/test/page-18.html
Will turn to  http://localhost/test/index.php  page

And in turn
http://localhost/test/index.html  The page doesn't show anything
http://localhost/test/index-99.html  Page shows  p : 99
http://localhost/test/page-18.html  Page shows  action : pageid : 18
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051247175304.html