.htaccess 尝试创建干净的 URL mod_rewrite

问题描述 投票:0回答:1

我已经阅读了之前的SO问题并阅读了教程,但我不完全理解mod_rewrite,所以我在这里发帖

Options +FollowSymLinks
RewriteEngine On

#Using THE_REQUEST for catching references and using them later on.
RewriteCond %{THE_REQUEST} \s/(content)/index\.php\?var=(.*?)\s [NC]
RewriteRule ^ /%1/featured/%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(content)/featured/(.*?)/?$ $1/index.php?var=$2 [QSA,NC,L]

RewriteRule ^profile/([0-9]+)/ /profile.php?userid=$3 [NC, L] 

我想带www。 domain.com / profile.php?userid=2343 并将 URL 重写为干净的 URL,即 www.domain 。 com/profile/2343/

我尝试了多种变体..上述 .htaccess 代码不起作用。

请帮忙?

.htaccess mod-rewrite clean-urls
1个回答
0
投票

根据您展示的尝试、样品。在测试您的网址之前,请确保清除浏览器缓存。

Options +FollowSymLinks
RewriteEngine On

#### 1st set of rules.... ####
#Using THE_REQUEST for catching references and using them later on.
RewriteCond %{THE_REQUEST} \s/(content)/index\.php\?var=(.*?)\s [NC]
RewriteRule ^ /%1/featured/%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(content)/featured/(.*?)/?$ $1/index.php?var=$2 [QSA,NC,L]


#### 2nd set of rules.... ####
#Using THE_REQUEST for catching references and using them later on.
RewriteCond %{THE_REQUEST} \s/(profile)\.php\?userid=(.*?)\s [NC]
RewriteRule ^ /%1%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(profile)/(.*?)/?$ $1.php?userid=$2 [QSA,NC,L]
© www.soinside.com 2019 - 2024. All rights reserved.