简体   繁体   English

htaccess mod_rewrite基于动态ID的不同URL

[英]htaccess mod_rewrite for different url based on dynamic id

hi everyone i have a problem in url customization i have 2 type of url 嗨,大家好,我在网址自定义方面遇到问题,我有2种网址

first is 首先是

http://domain/index.php?slug=pagename

i want it as http://domain/pagename 我希望它作为http://domain/pagename

2nd is 第二个是

http://domain/index.php?slug=pagename&id=id i want it as http://domain/pagename/id http://domain/index.php?slug=pagename&id=id我希望将其作为http://domain/pagename/id

my htaccess is 我的htaccess是

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.+)$

RewriteRule ^ https://%1%{REQUEST_URI} [L,R]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^?]*)$ index.php?slug=$1 

IndexIgnore *

Try this : 尝试这个 :

RewriteEngine on

RewriteCond %{THE_REQUEST} /index\.php\?slug=([^&]+)&id=([^\s]+) [NC]
RewriteRule ^ %1/%2? [NC,L,R]

RewriteCond %{THE_REQUEST} /index\.php\?slug=([^\s&]+) [NC]
RewriteRule ^ %1? [NC,L,R
RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^/]+)/?$ index.php?slug=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^/]+)/([^/]+)/?$ index.php?slug=$1&id=$2 [QSA,NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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