3

I am trying to redirect http://test.pearlsquirrel.com/explore_all?u=hiphop to http://test.pearlsquirrel.com/explore_all/hiphop using htaccess. However, It keeps redirecting here: http://test.pearlsquirrel.com/explore_all/?u=site_error.php. I have looked all over Stackoverflow for the answer but I just can't seem to find it. I would really appreciate some help in fixing this problem, thanks!

Here is my .htaccess file

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.pearlsquirrel.com$ [NC]
RewriteRule ^(.*)$ http://pearlsquirrel.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) explore_all?u=$1 [L]

1 Answer 1

2

You may try this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING}  [^=]+=([^=]+)
RewriteRule .* /%1? [L]

Will map this:

http://test.pearlsquirrel.com/explore_all?u=hiphop

To this:

http://test.pearlsquirrel.com/explore_all/hiphop

Replace the corresponding code in your .htaccess file with this one.

I have not checked the rules in your .htaccess file.

OPTION

Now, if it is the other way around, which I think it is, and the idea is to map this incoming URL:

http://test.pearlsquirrel.com/explore_all/hiphop

To this resource:

http://test.pearlsquirrel.com/explore_all?u=hiphop

Replace the above rule set with this one:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  .*/([^/]+)/?
RewriteRule .* http://test.pearlsquirrel.com/explore_all?u=%1 [L] 
Sign up to request clarification or add additional context in comments.

4 Comments

This still does not seem to sovve the problem. i get a 404 not found error when I try to go to the link test.pearlsquirrel.com/explore_all/hiphop.
¿Does /hiphop directory exists? You say: http://test.pearlsquirrel.com/explore_all?u=hiphop to http://test.pearlsquirrel.com/explore_all/hiphop, I think it should be the other way around. The URL shown in the browser address bar should be this one: http://test.pearlsquirrel.com/explore_all/hiphop not the first one, but I just answered your question. If so, update your question and I will gladly update my answer.
The directory does not exist. Should the directory exist? Sorry for any confusion that this has caused.
Look my previous comment. I think what you want is the opposite of what you asked. I will update the answer.

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.