伪静态功能实例

By | 2013年12月27日

伪静态实现的原理就是 index.php?act=about&cid=1 将这种形式的动态路径用 about-1.html 这种形式输出,根据不同的服务器环境,配置方法也不太一样,PHP+iis6的话就要配置httpd.ini文件,php+iis7就要配置web.config,PHP+apache就要配置.htaccess文件(php+iis现在新版好象已与apache的方法完全兼容)
.htaccess规则示例:
RewriteEngine on

RewriteRule ^/?(index|guestbook|online)\.html$ index\.php [L]

RewriteRule ^/?(eindex)\.html$ index\.php?act=$1 [L]

RewriteRule ^/?(index|guestbook|online)-([0-9]+).html$ index\.php\?p=$2 [L]

RewriteRule ^/?([a-z0-9]+)_([0-9]+).html$ index\.php\?act=$1&id=$2 [L]

RewriteRule ^/?([a-z0-9]+)-([0-9]+).html$ index\.php\?act=$1&cid=$2 [L]

RewriteRule ^/?([a-z0-9]+)-([0-9]+)-([0-9]+).html$ index\.php\?act=$1&cid=$2&p=$3 [L]

httpd.ini示例:
[ISAPI_Rewrite]

RepeatLimit 32

# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [F,I,O]

# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]
RewriteRule ^/(index|guestbook|online)\.html$ /$1\.php

RewriteRule ^/(eindex).html$ /index\.php\?act=$1

RewriteRule ^/(index|guestbook|online)-([0-9]+).html$ /$1\.php\?p=$2

RewriteRule ^/([a-z0-9]+)_([0-9]+).html$ /index\.php\?act=$1&id=$2

RewriteRule ^/([a-z0-9]+)-([0-9]+).html$ /index\.php\?act=$1&cid=$2

RewriteRule ^/([a-z0-9]+)-([0-9]+)-([0-9]+).html$ /index\.php\?act=$1&cid=$2&p=$3
web.config实例
How to make SEO friendly URL’s for Opencart on IIS Server
Uncategorized by admin
We all know how to rewrite urls for opencart on Linux servers. but if you are one of those who have opencart installed on windows servers then you must have faced issues with URL rewriting.
So here we go, just follow this simple steps and your opencart application can have SEO friendly URLs on IIS server too.
Log in to the admin panel -> go to System ?C Settings . Click on Edit -> go to server tab and click yes for SEO friendly urls.
Well this is the easy step.
Now a bit of coding stuff.
Create a web.config file, so remember that what .htaccess file is to Apache server, we.config is to IIS server.
web.config code start

<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Imported Rule 1″ stopProcessing=”true”>
<match url=”^(.*)$” ignoreCase=”false” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^yourdomain\.com$” />
</conditions>
<action type=”Redirect” redirectType=”Permanent” url=”http://www.yourdomain.com/{R:1}” />
</rule>
<rule name=”Imported Rule 2″ stopProcessing=”true”>
<match url=”^(.*)$” ignoreCase=”false” />
<conditions>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” ignoreCase=”false” negate=”true” />
<add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” ignoreCase=”false” negate=”true” />
<add input=”{URL}” pattern=”^/favicon.ico$” ignoreCase=”false” negate=”true” />
</conditions>
<action type=”Rewrite” url=”index.php?_route_={R:1}” appendQueryString=”true” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

web.config code end
Just copy paste the above code in your web.config file and upload it on your server. Voila! SEO URL enabled.
Now for those nerds who need a bit of technical explanation.
The first rewrite rule will helps in redirecting the website from naked domain to?www.domainname. This is very good for Google SEO.
The second re write rule will simply remove the index.php?_route_= and put the SEO key word of the category that you just entered.
So enjoy Opencart and have a good day!

 

 

如何使用Opencart的伪静态功能

第一:要确保你的appache服务器开启了mod_rewrite。具体如何开启和确认你的apache是否启用了mod_rewrite

第二:修改网站根目录下的.htaccess.txt为.htaccess文件,在windows环境下去掉.txt时,会有一个错误提示,可以按照如下方式修改:

(1)用记事本打开,点击文件?C另存为,在文件名窗口输入”.htaccess”,注意是整个绿色部分,也就是包含英文引号,然后点击保存就行了。

(2)进入cmd命令窗口,通过cd切换当刚建立htaccess.txt文件的文件夹,然后输入命令:rename htaccess.txt .htaccess?,然后点击键盘Enter键即可。

(3)通过ftp连接htaccess.txt所在文件夹,通过ftp软件重命名。

第三:登录后台,找到系统设置->商店设置->服务器设置把“高级URL Rewrite’s:”项改选成“是”

第四:添加商品或者栏目时,只要填写“SEO?关键字”,就会前台看到路径由”index.php?route=xx/xx”的方式变成了www.xxxx.com/你填写的seo关键词/.

以上设置环境都是在windows下的xampp包的apache和opencart中文环境下进行。其他环境参考设置。

注意事项:

1、如果你和我一样是在本地使用xampp包测试opencart,访问opencart的路径是localhost/opencart,那么做好以上设置后,请记得修改.htaccess文件中的“RewriteBase /”修改为“RewriteBase/opencart/”否则会出现找不到地址的问题。

2、如果是其他问题,请查看你的apache的log。

发表回复