12 Replies - 1460 Views - Last Post: 01 March 2016 - 03:30 PM

#1 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Apache redirects

Posted 29 February 2016 - 04:25 AM

Hi all,

How would I edit my .htaccess file so that whenever I append the query string "&test" to a URL, it shows me the appropriate URL in the development folder? For example:

www.example.com/blah.php?query=yes would show a page on my live site
www.example.com/blah.php?query=yes&test would show that page on my development site

Would I need to make 1:1 rules between pages, or is there something simpler I'm missing?

Thanks,
Zel2008

Is This A Good Question/Topic? 0
  • +

Replies To: Apache redirects

#2 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4238
  • View blog
  • Posts: 13,433
  • Joined: 08-June 10

Re: Apache redirects

Posted 29 February 2016 - 04:28 AM

Quote

Would I need to make 1:1 rules between pages

no. you can use RegExp to match the URLs.
Was This Post Helpful? 0
  • +
  • -

#3 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Re: Apache redirects

Posted 29 February 2016 - 11:42 AM

Thank you Dormlich,

I'm realizing this might not be what I need, and I'm not fully sure what I need in Apache. My scenario is this:

In my source code, I have things like:
<ul>
    <li><a href="http://www.example.com/page?page1">One</a></li>
    <li><a href="http://www.example.com/page?page2">Two</a></li>
</ul>



In my dev area, is there a way using Apache to make the code be interpreted like:

<ul>
    <li><a href="http://www.example.com/devArea/page?page1">One</a></li>
    <li><a href="http://www.example.com/devArea/page?page2">Two</a></li>
</ul>



Without actually changing the source code?

Thanks,
Zel2008
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,442
  • Joined: 10-May 07

Re: Apache redirects

Posted 29 February 2016 - 12:13 PM

Mod rewrite is what I believe you are looking for.

Moving to webservers & Hosting.
Was This Post Helpful? 0
  • +
  • -

#5 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Re: Apache redirects

Posted 29 February 2016 - 04:55 PM

Thanks for the move, didn't realize I was in the wrong forum.

So, I'm trying mod-rewrite, and so far I've got this in my .htaccess in my devArea folder:

# Rewriting identical production URLs for testing
DocumentRoot "/mydomain/public_html"
<Directory "/pageTemplate">
    RewriteEngine On
    RewriteBase "/devArea/pageTemplate/"
</Directory>
<Directory "/ui">
    RewriteEngine On
    RewriteBase "/devArea/ui/"
</Directory>

# Alternate index page
DirectoryIndex /ui/blah.php?page=login



It seems like this should work, based on what I've read of mod-rewrite, since my folder structure is;

public_html
    ui
    pageTemplate
    devArea
        ui
        pageTemplate



But, whenever I try to access something in the dev area, including the index page, I get a blank page back. No errors or anything. I have a feeling this is a bit farther out than what I know about Apache configs; would someone mind explaining what I'm doing wrong, please?
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,442
  • Joined: 10-May 07

Re: Apache redirects

Posted 29 February 2016 - 08:35 PM

Generally the mod-rewrite will work the other way around. Someone passes example.com/one/two/three & mod-rewrite converts & passes as get arguments example.com?arg=one&value=two&test=three

Reference : http://mod-rewrite-cheatsheet.com/
Verify with : http://htaccess.mwl.be/
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,442
  • Joined: 10-May 07

Re: Apache redirects

Posted 01 March 2016 - 10:03 AM

Another resource for query strings : here
Was This Post Helpful? 0
  • +
  • -

#8 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Re: Apache redirects

Posted 01 March 2016 - 11:04 AM

Sorry, I still don't get it -- so mod-rewrite won't work for this?
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,442
  • Joined: 10-May 07

Re: Apache redirects

Posted 01 March 2016 - 11:23 AM

View PostZel2008, on 29 February 2016 - 06:55 PM, said:

It seems like this should work, based on what I've read of mod-rewrite, since my folder structure is;

public_html
    ui
    pageTemplate
    devArea
        ui
        pageTemplate


So I can have a better understanding :

public_html/ui <-- this resource is a directory, yes or no?
public_html/ui/devArea <-- this resource is a directory, yes or no?
public_html/ui/devArea/ui <-- this resource is a directory, & it's contents are not the same as public_html/ui ?

So you want ui (when specified in the url get array) to be forwarded to ui/devArea/ui ?

With all of your attempts using one argument, my concern is even providing you a working example won't work on your server. That's why I pointed you at the documentation, so you can see that your setup is incorrect. Secondly, I can't just say : "this is the correct setup" because in your first example you used one url, in the 2nd you used another example url, & in the 3rd, you're introducing yet another style of url.

To recap, you can't use the directory directive & push a url with mod-rewrite on a single argument, & then flip to another directory directive & do something else. The way you have it here is just "magic", & it's syntax & logic are incorrect. Please provide your code using the url href, & then I'll write up an example adding on a get array element "test" to force it to work.
Was This Post Helpful? 0
  • +
  • -

#10 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Re: Apache redirects

Posted 01 March 2016 - 12:37 PM

Thanks --

public_html is my root directory.
public_html/ui contains production UI code.
public_html/pageTemplate contains production template code.

public_html/devArea is my development area directory.
public_html/devArea/ui contains development UI code.
public_html/devArea/pageTemplate contains development template code.

My original idea was to access development code for testing by appending "&test" to the query string. But, I realized that meant I would need to mess with static code, like link addresses, before migrating to production.

So, what I want to do is, if I'm in the dev area and I have code like this:
<a href="/pageTemplate/blah.html">link</a>

I want that link to redirect to the file "/pageTemplate/blah.html" that's in the dev area (/devArea/pageTemplate/blah.html). When that link is in production code, however, I want it to redirect as written

Does that make sense?

Thanks for the help so far!
Was This Post Helpful? 0
  • +
  • -

#11 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,442
  • Joined: 10-May 07

Re: Apache redirects

Posted 01 March 2016 - 12:51 PM

If you are in /devArea/, then based on relative root "pageTemplate/blah.html" will like to the correct resource /devArea/pageTemplate/blah.html. You would then only need a single mod-rewrite to remove /devArea/ from the url, & do nothing with non test. So help me understand how test gets added to the get array?
Was This Post Helpful? 0
  • +
  • -

#12 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Re: Apache redirects

Posted 01 March 2016 - 02:53 PM

The get array was my first idea, but then I decided against doing that. All I want to do now is know how, if I'm in the dev area, I can use mod-rewrite to make a URL that is written in the code to come from the production root (like /pageTemplate/blah.html) come from the dev area instead (/devArea/pageTemplate/blah.html).

EDIT: I am a moron. For some reason I was obsessed with rewriting URLs and didn't think of using relative URLs with a dynamic base tag. Sorry to waste your time.

This post has been edited by Zel2008: 01 March 2016 - 03:28 PM

Was This Post Helpful? 1
  • +
  • -

#13 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,442
  • Joined: 10-May 07

Re: Apache redirects

Posted 01 March 2016 - 03:30 PM

It's not a waste of time, it's a great tool to have. But you should have a better understanding of Apache & interactions first :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1