.htaccess 我有一个困难的时间重写我的网址在htaccess更搜索引擎优化友好

kiayqfof  于 2023-02-24  发布在  其他
关注(0)|答案(1)|浏览(113)

我当前的.htaccess文件如下所示:

RewriteEngine on
RewriteRule ^pages/([\w-]+)/artwork/?$ painting.php?painting=$1 [QSA,NC,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

我试图使网址,而不是看起来像example.com/artwork/paintingURL,我得到这个页面从<a href = "painting?painting=<?=$paintingURL?>"> .我已经在这里搜索,我已经得到的解决方案,没有一个答案似乎为我工作.
更新:使用下面的RavinderSingh13的解决方案后,我现在得到404页面未找到错误的重定向网址.在painting.php

<?php    
 if(isset($_GET['painting'])) {
 include('include/conn.php');    
 $paintingURL = $_GET['painting'];    
 $sql = "SELECT * FROM `paintings` WHERE `painting_URL` = '$paintingURL'";
 $result = $conn->query($sql);
    
 global $paintingName;
 global $paintingDesc;
 global $paintingImg;
 global $pageTitle;
    
  if(mysqli_num_rows($result) > 0){
   while ($row = mysqli_fetch_assoc($result)){
     
     $paintingName = $row['painting_Name'];
     $pageTitle = "Site Name - ".$paintingName;
     $paintingDesc = $row['size_description'];
     $paintingImg = $row['image_ID'];
  }    
} ?>

jsfiddle,用于链接的服务方式:https://jsfiddle.net/h65u9fc3/

pftdvrlh

pftdvrlh1#

使用显示的示例,请尝试以下.htaccess规则文件。

请确保:

  • 将.htaccess rules文件与project-name文件夹放在沿着。
  • 确保在测试URL之前清除浏览器缓存。
RewriteEngine ON
RewriteBase /project-name/

RewriteCond %{THE_REQUEST} \s/(project-name)/painting\?painting=(\S+)\s [NC]
RewriteRule ^ /%1/artwork/%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(project-name/artwork/)([^/]*)/?$ project-name/painting.php?painting=$1 [QSA,NC,L]

相关问题