繁体   English   中英

如何使用htaccess在干净的URL结构中进行重写

[英]How the rewrite in clean url structure with htaccess

我更改了网站的结构:删除了/ nl /文件夹,并将下划线切换为条纹。 因此,我们希望将旧页面重定向:www.example.com/nl/citygames_leuven到http://www.example.com/citygames-leuven

重定向工作了一段时间; 但是我的干净URL重定向出现问题。 我被重定向到: http : //www.example.com/citygames-leuven? url=nl/ citygames_leuven

正如你看到的; url参数插入并在页面上显示错误。

这是我到目前为止的代码:

Options All -Indexes 
RewriteEngine On 
RewriteBase / 


RewriteRule ^teambuilding/(.*)/?$ teambuilding.php?url=$1 [L]
RewriteRule ^citygame/(.*)/?$ citygame.php?url=$1 [L]
RewriteRule ^meeting/(.*)/?$ meeting.php?url=$1 [L]
RewriteRule ^aanzee/(.*)/?$ aanzee.php?url=$1 [L]
RewriteRule ^vip/(.*)/?$ vip.php?url=$1 [L]
RewriteRule ^verhuur/(.*)/?$ verhuur.php?url=$1 [L]
RewriteRule ^nieuws/(.*)/?$ nieuws.php?url=$1 [L]


#Url omzetten naar index.php?page= 
RewriteCond %{REQUEST_FILENAME} !-f [NC] 
RewriteCond %{REQUEST_FILENAME} !-d [NC] 
RewriteRule ^(.+)$ page.php?url=$1 [QSA] 



Redirect 301 /nl/citygames_antwerpen http://www.example.com/citygames-antwerpen
Redirect 301 /nl/citygames_leuven http://www.example.com/citygames-leuven
Redirect 301 /nl/teambuilding/offroad_buggy http://www.example.com/teambuilding/offroad-buggy

重新排列规则并在内部重写规则之前放置301:

Options All -Indexes 
RewriteEngine On 
RewriteBase / 

RewriteRule ^nl/citygames_antwerpen/?$ /citygames-antwerpen [L,R=301]
RewriteRule ^nl/citygames_leuven/?$ /citygames-leuven [L,R=301]
RewriteRule ^nl/teambuilding/offroad_buggy/?$ /teambuilding/offroad-buggy [L,R=301]

RewriteRule ^teambuilding/(.*)/?$ teambuilding.php?url=$1 [L]
RewriteRule ^citygame/(.*)/?$ citygame.php?url=$1 [L]
RewriteRule ^meeting/(.*)/?$ meeting.php?url=$1 [L]
RewriteRule ^aanzee/(.*)/?$ aanzee.php?url=$1 [L]
RewriteRule ^vip/(.*)/?$ vip.php?url=$1 [L]
RewriteRule ^verhuur/(.*)/?$ verhuur.php?url=$1 [L]
RewriteRule ^nieuws/(.*)/?$ nieuws.php?url=$1 [L]

#Url omzetten naar index.php?page= 
RewriteCond %{REQUEST_FILENAME} !-f [NC] 
RewriteCond %{REQUEST_FILENAME} !-d [NC] 
RewriteRule ^(.+)$ page.php?url=$1 [L,QSA] 

PS:最好在mod_rewrite本身中执行此操作,并避免使用mod_alias规则。

暂无
暂无

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

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