简体   繁体   中英

How to rewrite dynamic URL to SEO Friendly URL?

I tried everything I see here in this site to rewrite dynamic url to SEO friendly URL.

Is it maybe because im using it in the localhost?

I try this but does not work also:

RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
RewriteRule ^index\.php/?(.*) /$1 [R,L]
RewriteCond $0 !^index\.php($|/)
RewriteRule .* index.php/$0 [L]

I also refer to an online dynamic url generator , but it doesn't work either. Please help.

I would like to rewrite these couple of URLs:

index.php?p=home
index.php?p=about me
index.php?p=contact me

You can use this one:

RewriteEngine on

RewriteBase /

 # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1

Then on your index.php page, all the variables will put accessible via $_GET['q']. If you further use $location=array_filter(explode('/',$_GET['q'])); then $location will be an array containing each directory, so www.mysite.com/firstdir/seconddir/thirddir will have $location[0] as 'firstdir' and $location[1] as 'seconddir' and so on. You could then compare these to url_aliases in your database to determine what content/template to display.

This also works for localhost for me, except I change the base url part from "/" to "/mycurrentconstructionsite/"

Hope that helps!

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