简体   繁体   中英

Apache Htaccess rewrite rules

I have to write a htaccess to rewrite the links as follows and also a redirection of 404 error pages to my sites root (home page)

www.example.com/index.php?page=find&name=detail&id=109&cid=8
www.example.com/index.php?page=find&name=detail&id=109
www.example.com/index.php?page=find&name=detail
www.example.com/index.php?page=find

should be rewritten to

www.example.com/find/name/detail/id/109/cid/8
www.example.com/find/name/detail/id/109
www.example.com/find/name/detail
www.example.com/find

Your htaccess rules,

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?file=$1 [L,QSA]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/cid/([0-9]+)/$ index.php?page=find&name=detail&id=109&cid=8 [L]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/$ index.php?page=find&name=detail&id=109 [L]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/$ index.php?page=find&name=detail [L]
RewriteRule ^([a-zA-Z]+)/$ index.php?page=find [L]
</IfModule>

Try:

RewriteEngine On
RewriteRule ^find$ index.php?page=find [L,QSA]
RewriteRule ^(find)/([^/]+)/([^/]+)(.*)$ /$1$4?$2=$3 [L,QSA]
FallbackResource /

Try this code:

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7$8=$9 [L]
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7 [L]
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5 [L]
RewriteRule (.*)/([a-zA-Z]*)/(.*)\.html index.php?itfpage=$1&$2=$3 [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