简体   繁体   English

.htaccess网址是在index.php中而不是profile.php中重写

[英].htaccess url rewrites in index.php and not profile.php

So I am pretty new to url rewritting and.htaccess in general. 因此,我通常对url重写和.htaccess还是陌生的。 I would like to rewrite the url below 我想重写下面的网址

/rewrite/profile/karis/2

as

/rewrite/profile.php?name=karis&id=2

so the code I have for my .htaccess is 所以我的.htaccess代码是

RewriteEngine on
RewriteRule ^profile profile.php

RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ profile.php?name=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ profile.php?name=$1&id=$2

So this works perfectly when I change everything to work for index.php but the same code does not work on profile.php . 因此,当我将所有内容都更改为对index.php都有效时,但对于profile.php ,相同的代码不起作用,则此方法非常有效。

The simple php code is 简单的php代码是

<?php
    if(isset($_GET['name']) && isset($_GET['id']))
    {
        echo "Hi ".$_GET['name'].", your id is ".$_GET['id'];   
    }
?>

Any Ideas why? 任何想法为什么?

Your rules can all be combined into one and first one is misplaced also. 您的规则可以全部合并为一个,并且第一个规则也放错了位置。 Try this in your /rewrite/.htaccess : /rewrite/.htaccess尝试以下/rewrite/.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /rewrite/

RewriteRule ^([\w-]+)/([0-9]+)/?$ profile.php?name=$1&id=$2 [L,QSA]

RewriteRule ^profile/?$ profile.php [L]

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

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