简体   繁体   中英

htaccess seo friendly urls and redirect

I'm currently trying to make urls more SEO friendly, the problem is they are only half working.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?name=$1 
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?name=$1

That's my code. It works to an extent, but I can load the page from both mysite.com/index.php?name=name and mysite.com/name/ ; where as I only want mysite.com/name/ to load and I want mysite.com/index.php?name=name to redirect to mysite.com/name/

Any suggestions? Thanks.

Try this one


RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index\.php\?name=([^&\s]*)\s [NC]
RewriteRule ^ %1? [R=301,L]

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

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