Adding the directory name to the SEF URL, as well as passing the id value without using it in the URL

I am new to .htaccess and rewriting functions. I searched many pages, but I could not find a solution. Here is my problem:

I have URLs in these formats in the kurum.php file:

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

so my regular url:

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

related part of my .htaccess:

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

Therefore, I can get the SEF URLs in this format:

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

I have two questions:

1. Can this URL be changed to this format using .htaccess without moving the kurum.php file to a new directory?

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

(I can add the / kurumlar directory via .htaccess, but my css link and image will not work)

2. Can I pass the id value without mentioning it in the SEF URL as follows:

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

If I cannot do this, do I only need to use the $ sef variable to select articles from the database? Is there a flaw in this?

I hope this is enough to explain my problem. Thanks.

+4
source share
1 answer

1. Can this URL be changed to this format using .htaccess without moving the kurum.php file to a new directory?

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

(I can add the / kurumlar directory via .htaccess, but my css link and image will not work)


I used the full image path inside the 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 as follows:

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


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

"Is there a flaw in this?"

Yes. String search is slower, then integer.

+1
source

Source: https://habr.com/ru/post/1445973/


All Articles