Solved

Problem with rewrite access

Posted on 2014-09-22
16
80 Views
Last Modified: 2014-10-02
In my .htaccess file I have the following but the problem is when i type mydomain.com/site/info/?id=234
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?site/(.*)$ /site/public/$1
</IfModule>

Open in new window


As soon as I type /?id=234 it redirects back to mydomain.com/site.  Is there any way to fix this.  What do I need to change in my .htaccess file
0
Comment
Question by:stargateatlantis
  • 9
  • 7
16 Comments
 

Author Comment

by:stargateatlantis
ID: 40337714
I tried the following but didn't work

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^/?site/(.*)$ /site/public/$1
RewriteCond %{QUERY_STRING} ^id=([^&]+)$
RewriteRule ^\enhance\site\$ %1/ [L]

</IfModule>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40337748
As your additional post demonstrates, only the URL - not the query string - is tested in RewriteRule.  To rewrite or redirect based on the query string, you need a RewriteCond directive.

Please post the specific information required to generate the rule(s) you need:
The URL the user types in
The URL that should be delivered in response
Should the user see the URL they typed, or the URL you are actually delivering?
0
 

Author Comment

by:stargateatlantis
ID: 40338190
So basically  I want the ability to type the following in the URL browser and the user should see what they have typed

http://www.mydomain.com/site/?id=1234

But the following .htaccess needs to be modified

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?site/(.*)$ /site/public/$1
</IfModule>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40338213
If I put http://www.mydomain.com/site/?id=1234 into my address bar, what page do you want it to go to on your site?
0
 

Author Comment

by:stargateatlantis
ID: 40338280
No page it should stay on the same page
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40338480
Then what page do you want redirected to that URL?
0
 

Author Comment

by:stargateatlantis
ID: 40338811
When the user types http://www.mydomain.com/site/?id=1234  it stays on that page

My Current .htaccess is this

The site files are located under /site/public

Thanks for the help

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?site/(.*)$ /site/public/$1
</IfModule>

Open in new window

0
 

Author Comment

by:stargateatlantis
ID: 40339066
I tried the following but it didn't work

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^/?site/(.*)$ /site/public/$1
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ site/?id=$1

</IfModule>

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 50

Expert Comment

by:Steve Bink
ID: 40339320
Let's start again.  You have a real, actual page on your site.  Let's call it URL-A.  The user browses to your site by typing "http://yourdomain.com/URL-B" into their address bar.  What I need to know:

What is the actual address for URL-A?
What is the actual address for URL-B?
Will the user see URL-A or URL-B in the address bar?
0
 

Author Comment

by:stargateatlantis
ID: 40339430
So when typing www.mysite.com/site it will access the following folder /site/public/.

When typing

www.mysite.com/site/subdir/?id=1

It will still access the folder on the server /site/public/.

I don't need the url rewritten to this
www.mysite.com/site/subdir/id/1

I just want it so that when i type any url variable after slash it will not redirect to www.mysite.com/site/
0
 

Author Comment

by:stargateatlantis
ID: 40339775
I tried the following but no luck

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?site/(.*)$ /site/public/$1
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ /site/?id=$1 [QSA]
</IfModule>

Open in new window

0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40340294
To restate, you want all unadorned requests to /site to be forwarded to /site/public.  If the request is adorned with a query string, then do not rewrite.  Is that correct?
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?site/(.*)$ /site/public/$1 [NC]

Open in new window

0
 

Author Comment

by:stargateatlantis
ID: 40340325
Thanks Steve so this is the issue as soon as i type a

http://www.mysite.com/site/dir/?id=1 
it redirects to http://www.mysite.com/site/ 
and there is no files in that directory.  

What should happen when the user types in
http://www.mysite.com/site/dir/?id=1 
the url shouldn't change but it should read all the files in the public folder that is why i have the following in my .htaccess now

What is throwing it off is the /?id=1 or any variables.  

Thanks for all the help guys I know its confusing.  

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?site/(.*)$ /site/public/$1
</IfModule>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40340341
So, if I browse to www.mysite.com/site/dir/?id=1, then you want it to actually look for www.mysite.com/site/public/dir/?id=1.  Is that correct?
RewriteRule ^/?site/(.*)$ /site/public/$1 [QSA]

Open in new window

0
 

Author Comment

by:stargateatlantis
ID: 40340679
If i browse to

 www.mysite.com/site/dir/?id=1

I want it to stay there

what is happening the site redirects to

 www.mysite.com/site/?id=1

which is wrong

Thanks Steve for the help
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40340733
How do you determine which URLs do *not* redirect to /site/public?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now