简体   繁体   中英

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

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 .

How do I configure the .htaccess to "convert" this link to this:

localhost/ecom/quem-somos

And when the .htaccess is written, my href should be like this:

localhost/ecom/quem-somos

or, should be like this:

localhost/ecom/index.php?pages=1&title=quem-somos

and the url is converted to the SEO friendly one?

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

<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.

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/
Notice /1/ on the end, it need to pass pages variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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