5

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.

Orkun Tuzel
  • 1,342
  • 10
  • 22

1 Answers1

2

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.

user4035
  • 22,508
  • 11
  • 59
  • 94
  • 1. After putting "/" before all the links, there's no problem about adding directory name to the url. (By the way, I didn't use $_REQUEST and I'm not sure if I have to) 2. I decided not to use ids, only alias..(they are not very long strings) Thank you :) – Orkun Tuzel Nov 14 '12 at 19:25
  • > "By the way, I didn't use $_REQUEST and I'm not sure if I have to". You don't have to use it. I just put it into my file to make sure, that all the variables are correctly processed by .htaccess. – user4035 Nov 14 '12 at 20:19