-1

I'm trying URL re-writing for the first time and I have the following URLS which need rewriting:

http://domain.com/hotels/index.php?ct=new delhi

I want this as

http://domain.com/hotels/hotels-in-new delhi
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Sumit Sharma
  • 29
  • 1
  • 8

1 Answers1

0
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /hotels/index\.php\?ct=(\S+) [NC]
RewriteRule ^ /hotels/hotels-in-%1? [R=301,L,B]  # Use QSD flag is Apache 2.4 or later

RewriteRule ^hotels-in-(.*)$ index.php?ct=$1 [L]
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • this generate url like: http://domain.com/hotels/hotels-in-jaipur?ct=jaipur, i dont want query string and also page not found error – Sumit Sharma Sep 29 '15 at 12:26
  • Apache version: Apache/2.2.27 – Sumit Sharma Sep 29 '15 at 13:08
  • @SumitSharma Can you provide line from apache access logs for the 404 error? As far as I can tell, the 404 should not occur at all – hjpotter92 Sep 29 '15 at 13:13
  • [30/Sep/2015:00:17:05 +0530] "GET /hotels/hotels-in-jaipur?ct=jaipur HTTP/1.1" 404 221 ::1 - - [30/Sep/2015:00:17:25 +0530] "OPTIONS * HTTP/1.0" 200 – Sumit Sharma Sep 29 '15 at 13:23
  • @SumitSharma You've put the second rule as well? Where is the htaccess file located? – hjpotter92 Sep 29 '15 at 13:26
  • hotels/ folder where the index.php file located – Sumit Sharma Sep 29 '15 at 13:28
  • @SumitSharma Updated reply above. – hjpotter92 Sep 29 '15 at 13:29
  • i have another issue pls help me solve this :) my url like domain.com/hotels-details/hotelcode=00007388&hotel_key=0&hnm=hotel-name&hct=new-delhi now what i need this should be rewrite like domain.com/hotels/hotel-name-in-new-delhi-hotelcode-hotelkey – Sumit Sharma Oct 07 '15 at 10:19
  • Ask a separate question @SumitSharma That would need a longer explanation – hjpotter92 Oct 07 '15 at 10:42
  • I am stoped by stack as i asked 2 questions as per your previous answer i will generate correct url as per my need but showing 404(page not found error pls check below) RewriteCond %{THE_REQUEST} ^GET\ /hotels-details\?hotelcode=(\S+)&hotel_key=(\S+)&hnm=(\S+)&hct=(\S+) [NC] RewriteRule ^ /hotel/%3-in-%4-%1-%2? [R=301,L,B] – Sumit Sharma Oct 07 '15 at 11:42
  • @SumitSharma At the end, you'd also need a new `RewriteRule ^hotels/(.*)-in-(.*?)-(\d+)-(\d+)/?$ /hotels-details/hotelcode=$3&hotel_key=$4&hnm=$1&hct=$2 [L]` – hjpotter92 Oct 07 '15 at 11:55