简体   繁体   中英

SEO Friendly URLs .htaccess

I'm working on the .htaccess file for creating SEO Friendly Urls. Still experimenting with it and it works good so far. I was looking to make it a bit more dynamic.

I want the URL structures to be similar to what is below, but I don't always know how many levels there will be.

http://website.com/level_1/level_2/level_3/level_4/

In the .htaccess file below I manually coded it to detect 2 levels of the URL. Is there a way I can make it check the last level and then work back from there to make it easier? So In other words if the URL had 3 levels it would detect that and then the RewriteRule would adjust to how many levels there are.

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-/]+)/$([a-zA-Z0-9-/]+)/$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9-/]+)/$([a-zA-Z0-9-/]+)$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9-/]+)/$ index.php?a=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ index.php?a=$1

通常,你最好做RewriteRule ^(.*)$ index.php?path=$1并允许你的index.php文件处理逻辑。

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