2

I am using below code on my .htaccess file

RewriteRule ^([^/]*)/([^/]*)$ /view_basket.php?order_id=$1&pin=$2 [L]

the goal is to redirect a clean URL like below

http://www.zire20.ir/77438/9512  

to this one

http://www.zire20.ir/view_basket.php?order_id=77438&pin=9512  

The thing is it was working on my previous server but now I changed to godaddy hosting and it's not working! any idea ?

p.s:

and my whole .htaccess file is like below:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^zire20.ir [NC]
RewriteRule ^(.*)$ http://www.zire20.ir/$1 [L,R=301]
RewriteRule ^([^/]*)/([^/]*)$ /view_basket.php?order_id=$1&pin=$2 [L]
8
  • Maybe you need to add #Fix Rewrite Options -Multiviews (see this article) Commented May 2, 2016 at 19:07
  • 1
    First what do you mean by it's not working. Are you getting errors or it's behaving differently then expected. . Commented May 2, 2016 at 19:17
  • You are right I should explained, it's causing abnormal behaviors in website, lots of photos are not loading! @panama jack Commented May 2, 2016 at 19:22
  • Have you tried RewriteCond %{HTTP_HOST} ^www.zire20.ir [NC] ? Commented May 2, 2016 at 19:26
  • @Wiktor I tried this one but didn't work! Commented May 2, 2016 at 19:27

1 Answer 1

1

RewriteRule ^([^/]*)/([^/]*)$ /view_basket.php?order_id=$1&pin=$2 [L]
lots of photos are not loading!

The problem with your current rule is that you are rewriting unconditionally. Any URL that contains a single slash will get rewritten. I imagine that some of your (static) photo URLs match this pattern.

Common practise is to only rewrite the URL if it doesn't match an existing file (or directory):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /view_basket.php?order_id=$1&pin=$2 [L]

This makes sure the request is only rewritten for non-existing files (not a file or a directory). I've also made the pattern a little more restrictive so there must be 1 or more chars before and after the slash (+), instead of 0 or more (*).

The thing is it was working on my previous server

I can't see how this was possible, unless the URL structure was different on the previous server?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.