Php URL重写规则不起作用。htaccess

Php URL重写规则不起作用。htaccess,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正在尝试使用.htaccess文件重写URL,但它不起作用。首先我在本地主机上做了很多尝试,然后在Live Server上做了很多尝试,但都不起作用。。我仍然得到了原始url。这就是我拥有的 原始URL:- <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule

我正在尝试使用.htaccess文件重写URL,但它不起作用。首先我在本地主机上做了很多尝试,然后在Live Server上做了很多尝试,但都不起作用。。我仍然得到了原始url。这就是我拥有的

原始URL:-

 <IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^([^/]*)\.php$ /specific_hall.php?hall_name=$1&hall_id=1 [L]
   </IfModule>

我想要:-

 <IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^([^/]*)\.php$ /specific_hall.php?hall_name=$1&hall_id=1 [L]
   </IfModule>

My.htaccess文件:-

 <IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^([^/]*)\.php$ /specific_hall.php?hall_name=$1&hall_id=1 [L]
   </IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^([^/]*)\.php$/specific\u hall.php?hall\u name=$1&hall\u id=1[L]

我仍在获取原始URL。。有人能指出为什么重写规则不起作用吗?我试了很多,但没有成功。提前感谢。

您需要在新的url格式中包含
hall_id
param,以便将其重写回来。否则,mod_rewrite无法知道这一点

您可以将此代码放在根目录中

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/specific_hall\.php\?hall_name=([^\s&]+)&hall_id=(\d+)\s [NC]
RewriteRule ^ %2-%1.php? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+)-([^/]+)\.php$ specific_hall.php?hall_name=$2&hall_id=$1 [L]
例如:

  • http://example.com/specific_hall.php?hall_name=Shalimar+大厅和大厅id=1
    将重定向到
    http://example.com/1-Shalimar+php
    (无需 更改文件中的链接)
  • http://example.com/1-Shalimar+php将在内部重写为(=
    显示与相同的内容)
    
    http://example.com/specific_hall.php?hall_name=Shalimar+大厅和大厅id=1

  • 您总是想要Shalimar-Hall.php,还是取决于Hall_name的值?感谢回复@Sunil Pachlangia。我想要的取决于hall_name的值..当你使用url时会发生什么???@sundar Bons它在我编写这个测试时起作用。1click.com.pk/Shalimar+hall.php但是当我点击链接获取特定的hall值时,它会显示原始url..这就是它将要做的。这是重写工作的方式,谢谢@justinlurman。它就像一个符咒。请更新此.htaccess文件以删除字符串之间的+符号。。e、 g(沙利玛+大厅)。。我要沙利玛厅或沙利玛厅。提前谢谢,不客气。是的,这是可能的。但是你能告诉我大厅的名字是否可以包含任何破折号吗?因为如果
    Shalimar+Hall
    变为
    Shalimar-Hall
    ,并且在其他地方有“本机”破折号,这将是一个问题。示例:如果
    hall\u name
    Something special
    ,则它将变成
    Something+special
    (这是不正确的)。实际上,您必须确保您选择的字符最初不在所有其他
    hall\u name
    可能的值中@贾斯汀·勒曼的名字可以包含破折号。。。感谢您的回复和时间…然后由您选择一个永远不会出现在
    hall\u name
    中的特殊字符(或者您可以保留
    +
    ,因为这对于引用和seo来说不是问题)