使用 .htaccess 在 php 中实现干净的 url
Using .htaccess to implement clean urls in php
我的主页设置为
/localhost/HobbyClub/index.php
我想将其设置为
/localhost/HobbyClub/home
这基本上是在实施清洁 URL。
我尝试了两种不同的密码:
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^localhost/HobbyClub$
RewriteRule ^(.*) localhost/HobbyClub/ [R=301,L]
RewriteRule ^home$ /index.php [L]
和
RewriteEngine On
RewriteRule ^$ /home [L]
两者均无效。在此之后,我也希望能够实现:
localhost/HobbyClub/club.php?id=1
重定向到
localhost/HobbyClub/club/Architecture
我在 Whosebug 上浏览了很多答案,但我自己无法实现。
您可以在 /HobbyClub/.htaccess
中使用此代码:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /HobbyClub/
RewriteRule ^home/?$ index.php [L,NC]
我的主页设置为
/localhost/HobbyClub/index.php
我想将其设置为
/localhost/HobbyClub/home
这基本上是在实施清洁 URL。
我尝试了两种不同的密码:
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^localhost/HobbyClub$
RewriteRule ^(.*) localhost/HobbyClub/ [R=301,L]
RewriteRule ^home$ /index.php [L]
和
RewriteEngine On
RewriteRule ^$ /home [L]
两者均无效。在此之后,我也希望能够实现:
localhost/HobbyClub/club.php?id=1
重定向到
localhost/HobbyClub/club/Architecture
我在 Whosebug 上浏览了很多答案,但我自己无法实现。
您可以在 /HobbyClub/.htaccess
中使用此代码:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /HobbyClub/
RewriteRule ^home/?$ index.php [L,NC]