简体   繁体   English

无法解决 htaccess 重写问题(对 seo 友好的 URL)

[英]Can't resolve htaccess rewrite issue (seo-friendly URL)

Hi.你好。 First of all I am very new to Stack Overflow so excuse me if I did something wrong.首先,我对 Stack Overflow 很陌生,如果我做错了什么,请见谅。

I need some help on the .htaccess to rewrite a rule for a SEO friendly URL.我需要 .htaccess 的一些帮助,以重写对 SEO 友好的 URL 的规则。 Basically it is a blog and I get blog post data not with an $id but with a sef URL parameter.基本上它是一个博客,我得到的博客文章数据不是带有 $id 而是带有 sef URL 参数。 I know that search engines does not like URL parameters because it is hard to identify what is what.我知道搜索引擎不喜欢 URL 参数,因为很难识别什么是什么。

"sef" parameter dynamically changes according to the blog post content I show. “sef”参数根据我展示的博文内容动态变化。 I want to get the part after "=" and delete parameter name(?sef) and put a "/" in between which looks like this.我想获取“=”之后的部分并删除参数名称(?sef)并在其间放置一个“/”,看起来像这样。

Current URL structure (with a "sef" parameter)当前的 URL 结构(带有“sef”参数)

https://www.dent.com.tr/gelismeler.php?sef=dis-tedavisi-nasil-genclestirir

I want to rewrite this url as我想将此 url 重写为

https://www.dent.com.tr/gelismeler/dis-tedavisi-nasil-genclestirir

I check/set page content data dynamically from a mysql database within gelismeler.php我从 gelismeler.php 中的 mysql 数据库动态检查/设置页面内容数据

if (isset($_GET['sef'])) {
$sef = $_GET['sef'];

$sql = "SELECT * FROM posts WHERE sef='$sef'";
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($query);

$title = $row["title"];
$desc = $row["description"];
$img = $row["image"];

I've tried countless variations but actually I've never succeed:(我尝试了无数种变化,但实际上我从未成功:(

Can anybody help me with this?有人可以帮我吗?

Thanks a lot!非常感谢!

My current.htacces file:我的 current.htacces 文件:

ErrorDocument 404 /404.php
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php

RewriteCond %{HTTP_HOST} !^www.dent.com.tr$
RewriteRule ^(.*)$ http://www.dent.com.tr/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html) [NC]
RewriteRule ^index\.php$ http://www.dent.com.tr/ [R=301,L]

Have it this way:有这种方式:

ErrorDocument 404 /404.php
Options -MultiViews
RewriteEngine On
RewriteBase /

# add www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# remove index.php or index.html
RewriteCond %{THE_REQUEST} \s/+index\. [NC]
RewriteRule ^index\.(html?|php)$ / [R=301,L,NC]

# external redirect from actual URL to pretty one
# 2 parameter redirect rule
RewriteCond %{THE_REQUEST} \s/+gelismeler\.php\?category=([^&]+)&sef=([^\s&]+)\s [NC]
RewriteRule ^ /gelismeler/%1/%2? [R=301,L,NE]

# 1 parameter redirect rule
RewriteCond %{THE_REQUEST} \s/+gelismeler\.php\?sef=([^\s&]+)\s [NC]
RewriteRule ^ /gelismeler/%1? [R=301,L,NE]

# internal forward from pretty URL to actual one
# 2 parameters rewrite
RewriteRule ^gelismeler/([\w-]+)/([\w-]+)/?$ gelismeler.php?category=$1&sef=$2 [L,QSA,NC]

# 1 parameter rewrite
RewriteRule ^gelismeler/([\w-]+)/?$ gelismeler.php?sef=$1 [L,QSA,NC]

# add .php internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

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

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