简体   繁体   English

将URL转换为SEO友好

[英]Convert URL to SEO Friendly

I have a few questions. 我有几个问题。 In my website, I have, for example, a link like this: 例如,在我的网站上,我有一个像这样的链接:

localhost/ecom/index.php?pages=1&title=quem-somos 本地主机/ecom/index.php?pages=1&title=quem-somos

The index file checks the GET['pages'] for the id, and assign two variables based on info from the db: $static_id , and $static_title . 索引文件检查GET['pages']的ID,并根据数据库中的信息分配两个变量: $static_id$static_title

How do I configure the .htaccess to "convert" this link to this: 如何配置.htaccess以将此链接“转换”为此:

localhost/ecom/quem-somos 本地主机/ ecom / quem-somos

And when the .htaccess is written, my href should be like this: 编写.htaccess时,我的href应该是这样的:

localhost/ecom/quem-somos 本地主机/ ecom / quem-somos

or, should be like this: 或者,应该像这样:

localhost/ecom/index.php?pages=1&title=quem-somos 本地主机/ecom/index.php?pages=1&title=quem-somos

and the url is converted to the SEO friendly one? 并将网址转换为SEO友好的网址?

Sorry if there's some stupid questions here, I've read a few blog posts but still can't figure it out. 抱歉,如果这里有一些愚蠢的问题,我已经读了一些博客文章,但仍然无法解决。

Put this one in your /ecom/ dir 将此放在您的/ ecom /目录中

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /ecom/

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_FILENAME} !\.(css|js|jpeg|jpg|gif|png|bmp)$
  RewriteRule ^([^\/]+)\/([^\/]+)\/?$ index.php?title=$1&pages=$2 [L,B,QSA]
</IfModule>

Maybe RewriteBase is no need, based on your serve configuration, so if some remove. 根据您的服务配置,也许不需要RewriteBase ,所以如果有的话,将其删除。

Or put this one variatn to your root dir 或者将此变量放在您的根目录下

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_FILENAME} !\.(css|js|jpeg|jpg|gif|png|bmp)$
  RewriteRule ^ecom\/([^\/]+)\/([^\/]+)\/?$ /ecom/index.php?title=$1&pages=$2 [L,B,QSA]
</IfModule>

I'm prefer first one. 我更喜欢第一个。 Your urls must be like http://localhost/ecom/some-title/1/ 您的网址必须类似于http:// localhost / ecom / some-title / 1 /
Notice /1/ on the end, it need to pass pages variable 注意/ 1 /最后,它需要传递页面变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM