5

我是一个关于 .htaccess 和重写函数的新手。我搜索了很多页面,但找不到解决方案。这是我的问题:

我的 kurum.php 文件中有这些格式的网址:

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

所以我的正常网址是:

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

我的 .htaccess 的相关部分是:

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

所以我可以得到这种格式的 SEF url:

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

我有两个问题:

1. 可以在不将 kurum.php 文件移动到新目录的情况下使用 .htaccess 将此 url 更改为这种格式吗?

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

(我可以通过 .htaccess 添加“/kurumlar”目录,但我的 css 和图像链接不起作用)

2. 我可以传递 id 值而不在 SEF url 中提及它,如下所示:

http://fxrehber.com/kurumlar/ata-foreks(这对我来说是最好的选择)

如果我不能这样做,我是否必须仅使用 $sef 变量从数据库中选择文章?这有缺点吗?

我希望这足以解释我的问题。谢谢你。

4

1 回答 1

2

1. 可以在不将 kurum.php 文件移动到新目录的情况下使用 .htaccess 将此 url 更改为这种格式吗?

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

(我可以通过 .htaccess 添加“/kurumlar”目录,但我的 css 和图像链接不起作用)


我在 php 文件中使用了图像的完整路径,它适用于:.htaccess:

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

库鲁姆.php:

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

2. 我可以传递 id 值而不在 SEF url 中提及它,如下所示:

http://fxrehber.com/kurumlar/ata-foreks(这对我来说是最好的选择)


只有 ifata-foreks可以作为文章的唯一别名,代替 id 使用。

“这有什么坏处吗?”

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

于 2012-11-14T13:04:33.743 回答