dqqy64515 2012-11-14 10:16
浏览 44
已采纳

将目录名称添加到SEF URL中,并在url中不使用它而传递id值

I'm a newbie about .htaccess and rewrite functions. I've searched many pages but I couldn't find a solution. Here's my problem:

I have urls in these formats in my kurum.php file:

fxrehber.com/kurum.php?id=$krmID&sef=$sef

so my normal url is:

http://fxrehber.com/kurum.php?id=7&sef=ata-foreks

related part of my .htaccess is:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
  RewriteRule ^([0-9]+)-([a-zA-Z0-9-_]+)$ /kurum.php?id=$1&sef=$2
</IfModule>

So I can get SEF urls in this format:

http://fxrehber.com/7-ata-foreks

I have two questions:

1 . Can this url changed into this format with .htaccess without moving kurum.php file into a new directory?

http://fxrehber.com/kurumlar/7-ata-foreks

(I can add "/kurumlar" directory by .htaccess but my css and image link won't work)

2 . Can I pass the id value without mentioning it in the SEF url like this:

http://fxrehber.com/kurumlar/ata-foreks (which is the best option for me)

If I cannot do this, do I have to use only $sef variable to select articles from the database? Is there a disadvantage about this?

I hope this is enough explanation about my problem. Thank you.

  • 写回答

1条回答 默认 最新

  • dousi8931 2012-11-14 13:04
    关注

    1 . Can this url changed into this format with .htaccess without moving kurum.php file into a new directory?

    http://fxrehber.com/kurumlar/7-ata-foreks

    (I can add "/kurumlar" directory by .htaccess but my css and image link won't work)


    I used full path of the image inside php file and it works with this: .htaccess:

    <IfModule mod_rewrite.c>
      Options +FollowSymlinks
      RewriteEngine On
      RewriteRule ^kurumlar\/([0-9]+)-([a-zA-Z0-9-_]+)$ /kurum.php?id=$1&sef=$2
    </IfModule>
    

    kurum.php:

    <?php
        var_dump($_REQUEST);
    ?>
    <img src="/sites/default/files/1.png">
    

    2 . Can I pass the id value without mentioning it in the SEF url like this:

    http://fxrehber.com/kurumlar/ata-foreks (which is the best option for me)


    Only if ata-foreks can be used as a unique alias of an article and used instead of id.

    "Is there a disadvantage about this?"

    Yes. Searching by string is slower, then by integer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。