使用Htaccess和php更改URL结构时出现问题

使用Htaccess和php更改URL结构时出现问题,php,.htaccess,Php,.htaccess,我在修复网站上的URL时遇到问题:我想将www.abelputra.com/software.php更改为www.abelputra.com/software 我读过一篇教程,其中提出了以下建议: 对于.htaccess: RewriteEngine On RewriteRule ^ ([a-zA-Z0-9_-] +) $ index.php? Key = $ 1 RewriteRule ^ ([a-zA-Z0-9_-]+)/$ index.php? Key = $ 1 然后在php中: in

我在修复网站上的URL时遇到问题:我想将
www.abelputra.com/software.php
更改为
www.abelputra.com/software

我读过一篇教程,其中提出了以下建议:

对于.htaccess:

RewriteEngine On
RewriteRule ^ ([a-zA-Z0-9_-] +) $ index.php? Key = $ 1
RewriteRule ^ ([a-zA-Z0-9_-]+)/$ index.php? Key = $ 1
然后在php中:

index.php--->

问题是,当我使用software.php和index.php实现菜单以调用页面时:

www.abelputra.com/index.php?key=software

所显示的页面是两个页面,下面是software.php和index.php页面

是因为我调用了“include()”函数吗

index.php结构:

  • 标题

  • 内容->包含开场白

  • 页脚

  • software.php结构:

  • 标题

  • 内容->包含对我的软件的说明

  • 页脚


  • 我不知道我是否理解正确,但如果您只想重写URL(如删除.php扩展名),则无需实现网关脚本或更改主页的逻辑代码(修改URL除外)

    例如,以下内容将允许您使用 abelputra.com/freetips/185

    RewriteRule ^freetips/(\d+)$ freetips_det.php?tip=$1 [L]
    
    一般扩展删除是一个众所周知的主题,这里讨论的示例如下:


    我的问题是如何在phpmy中实现它,我的解决方案是如何不需要实现它,因为您的主页已经在运行,您只想更改一些URL,我的网站正在运行。但我看到他们删除了大多数其他的websites.php,并将其变成一个文件夹。根据我的说法,不要忽略php扩展。我只是不知道如何在我的php脚本中实现它。
    RewriteRule ^freetips/(\d+)$ freetips_det.php?tip=$1 [L]
    
    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    
    RewriteBase /
    
    ## hide .php extension
    
    # To externally redirect /dir/foo.php to /dir/foo
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    
    RewriteRule ^ %1 [R,L,NC]
    
    ## To internally redirect /dir/foo to /dir/foo.php
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    
    RewriteRule ^ %{REQUEST_URI}.php [L]