简体   繁体   English

URL重写规则不起作用.htaccess

[英]URL Rewrite Rule not working .htaccess

I am trying to Rewrite the URL using .htaccess file but it is not working. 我正在尝试使用.htaccess文件重写URL,但无法正常工作。 First I tried a lot on my localhost and then on my Live Server but it's not working.. I still get the original url .That is what I have.. 首先,我在本地主机上进行了很多尝试,然后在Live Server上进行了尝试,但是它不起作用..我仍然得到原始的URL 。这就是我所拥有的。

Original URL:- 原始网址:-

http://test.1click.com.pk/specific_hall.php?hall_name=Shalimar+Hall&hall_id=1 http://test.1click.com.pk/specific_hall.php?hall_name=Shalimar+Hall&hall_id=1

I Want:- 我想要:-

http://test.1click.com.pk/Shalimar+Hall.php http://test.1click.com.pk/Shalimar+Hall.php

My .htaccess file:- 我的.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>

I am still getting the original URL.. Can anybody please point out that why rewrite rule is not working? 我仍在获取原始URL。.有人可以指出为什么重写规则不起作用吗? I tried a lot with no success. 我尝试了很多但没有成功。 Thanks in Advance. 提前致谢。

You need to include hall_id param in your new url format in order to rewrite it back. 您需要以新的url格式包含hall_id参数,以便将其重写。 Otherwise, mod_rewrite has no way to know it. 否则, mod_rewrite无法知道它。

You can put this code in your root htaccess 您可以将此代码放在根htaccess中

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]

Example: 例:

  1. http://example.com/specific_hall.php?hall_name=Shalimar+Hall&hall_id=1 will redirect to http://example.com/1-Shalimar+Hall.php (no need to change links in your files). http://example.com/specific_hall.php?hall_name=Shalimar+Hall&hall_id=1将重定向到http://example.com/1-Shalimar+Hall.php (无需更改文件中的链接)。
  2. http://example.com/1-Shalimar+Hall.php will internally rewrite to (= display the same content as) http://example.com/specific_hall.php?hall_name=Shalimar+Hall&hall_id=1 http://example.com/1-Shalimar+Hall.php将在内部重写为(=显示http://example.com/specific_hall.php?hall_name=Shalimar+Hall&hall_id=1相同的内容) http://example.com/specific_hall.php?hall_name=Shalimar+Hall&hall_id=1

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

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