删除URL部分并使用htaccess重写它

时间:2022-01-23 10:50:51

My website has urls like http://domain.com/index.php?page=events/eventdetails/1/Silver+Jubilee, http://domain.com/index.php?page=events/announcementdetails/2, http://domain.com/index.php?page=events/announcementdetails/3 etc which I want to change to http://domain.com/Events/Eventdetails/1/Silver+Jubilee, http://domain.com/Announcements/Announcementdetails/3 .

我的网站有http://domain.com/index.php?page=events/eventdetails/1/Silver+Jubilee,http://domain.com/index.php?page = event / announcesdetails/2,http ://domain.com/index.php?page = events / announcementdetails / 3等我想更改为http://domain.com/Events/Eventdetails/1/Silver+Jubilee,http://domain.com / Announcements / Announcementdetails / 3。

Currently my htaccess file is as shown below in which I am doing URL rewriting for some other pages.

目前我的htaccess文件如下所示,其中我正在为其他一些页面进行URL重写。

Options +FollowSymLinks
RewriteEngine On
RewriteRule  AboutUs$ /index.php?page=home/aboutus [QSA,L]
RewriteRule  Announcements$ /index.php?page=events/announcements [QSA,L]
RewriteRule  Church-Officials$ /index.php?page=account/official [QSA,L]
RewriteRule  PhotoGallery$ /index.php?page=gallery/album [QSA,L]
RewriteRule  VideoGallery$ /index.php?page=videogallery/videos [QSA,L]
RewriteRule  ContactUs$ /index.php?page=home/contactus [QSA,L]
RewriteRule  Vicar-Message$ /index.php?page=events/allmessages [QSA,L]
RewriteRule  Events$ /index.php?page=events/event [QSA,L]
RewriteRule  Gallery-Images$ /index.php?page=gallery/photos [QSA,L]

RewriteRule ^/(.*)$ /index.php?page=$1 [QSA,L]

How it can be done using htaccess? Can anyone help me to do it. Thanks in advance.

如何使用htaccess完成?谁能帮助我做到这一点。提前致谢。

1 个解决方案

#1


0  

Add this to your .htaccess in your web root / directory

将其添加到Web根目录/目录中的.htaccess

RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /index\.php\?page=([^\s]+) [NC]
RewriteRule ^ http://domain.com/%1 [R=301,L]

RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\ /index\.php [NC]
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

#1


0  

Add this to your .htaccess in your web root / directory

将其添加到Web根目录/目录中的.htaccess

RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /index\.php\?page=([^\s]+) [NC]
RewriteRule ^ http://domain.com/%1 [R=301,L]

RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\ /index\.php [NC]
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]