Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-10-2011, 01:11 AM   PM User | #1
cineweekly.com
Regular Coder

 
cineweekly.com's Avatar
 
Join Date: Aug 2010
Posts: 485
Thanks: 14
Thanked 3 Times in 3 Posts
cineweekly.com can only hope to improve
Can I rewrite my urls to display as one directory higher?

If my articles actual location is:
example.com/sunday/article.php

How can I rewrite all articles in 'sunday' to appear as:
example.com/article.php
__________________
¿¿¿ curious ???
cineweekly.com is offline   Reply With Quote
Old 01-10-2011, 03:25 AM   PM User | #2
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
Yes, you'll want to use the mod_rewrite apache module.

Here's a link to a post where I provided a detailed explanation, as well as a very helpful tutorial, on how this can be achieved:

http://www.codingforums.com/showpost...40&postcount=4
__________________
Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com
ShaneC is offline   Reply With Quote
Old 01-10-2011, 03:54 AM   PM User | #3
cineweekly.com
Regular Coder

 
cineweekly.com's Avatar
 
Join Date: Aug 2010
Posts: 485
Thanks: 14
Thanked 3 Times in 3 Posts
cineweekly.com can only hope to improve
Quote:
Originally Posted by ShaneC View Post
Yes, you'll want to use the mod_rewrite apache module.

Here's a link to a post where I provided a detailed explanation, as well as a very helpful tutorial, on how this can be achieved:

http://www.codingforums.com/showpost...40&postcount=4
I keep re-reading but I can't customize Apache stuff at all. I have no idea on the syntax and codes or anything. Could you give me the code to make every url in a sub-folder appear like it's in the root folder and then I can just switch out sub-folder names to customize it? I don't have any dynamically created pages.
__________________
¿¿¿ curious ???
cineweekly.com is offline   Reply With Quote
Old 01-10-2011, 04:07 AM   PM User | #4
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
The method there is geared towards dynamic pages but it can be adjusted to static as well. As for modifying Apache you can use this with an .htaccess file. Create a file named ".htaccess" and place it in the root of your web directory (typically public_html/ or www/).

Now unfortunately I don't have access to an Apache installation and I'm terrible at REGEX. So I'll do my best to help you out however if anyone else is viewing this that has a better method please chime in.

In your .htaccess file try putting in:

Code:
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)$ sunday/$1
Let me know what happens and we can take it from there.
__________________
Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com
ShaneC is offline   Reply With Quote
Old 01-10-2011, 04:35 AM   PM User | #5
cineweekly.com
Regular Coder

 
cineweekly.com's Avatar
 
Join Date: Aug 2010
Posts: 485
Thanks: 14
Thanked 3 Times in 3 Posts
cineweekly.com can only hope to improve
I am slightly familiar with .htaccess and have some redirects set up but mostly automated through hosting site.
I added:
Code:
RewriteBase /
...directly under 'RewriteEngine On' which was already there. Then I placed:
Code:
RewriteRule ^(.*)$ sunday/$1
...both first and last and I was getting "Internal Server Error" on my whole site. Sooo close.
__________________
¿¿¿ curious ???
cineweekly.com is offline   Reply With Quote
Old 01-10-2011, 04:59 AM   PM User | #6
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
Did you also include RewriteEngine On? And your .htaccess, or the rewrite part anyway, should appear exactly as in my post (in that order and all).
__________________
Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com
ShaneC is offline   Reply With Quote
Old 01-10-2011, 05:03 AM   PM User | #7
cineweekly.com
Regular Coder

 
cineweekly.com's Avatar
 
Join Date: Aug 2010
Posts: 485
Thanks: 14
Thanked 3 Times in 3 Posts
cineweekly.com can only hope to improve
Here's what I have (previous stuff in red).

Code:
ErrorDocument 404 /errors/404.php

RewriteEngine on
RewriteBase /

RewriteRule ^(.*)$ sunday/$1

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

RewriteCond %{HTTP_HOST} ^u-stu.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.u-stu.com$
RewriteRule ^/?$ "http\:\/\/www\.cineweekly\.com\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^cineweekly.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.cineweekly.com$
RewriteRule ^index\.php$ "http\:\/\/www\.cineweekly\.com\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^cineweekly.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.cineweekly.com$
RewriteRule ^images\/?$ "http\:\/\/www\.cineweekly\.com\/" [R=301,L]
__________________
¿¿¿ curious ???
cineweekly.com is offline   Reply With Quote
Old 01-10-2011, 05:37 AM   PM User | #8
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
Edit: These won't work. I'm trying some things on my Apache server. I'll post back if I have anything.


Okay, three ideas.

First, try putting the RewriteRule I posted below all the other RewriteRules.

Second, try using this RewriteRule instead:

Code:
RewriteRule ^/(.*)$ sunday/$1
Third, if you remove this RewriteRule does the server error go away?
__________________
Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com

Last edited by ShaneC; 01-10-2011 at 05:47 AM..
ShaneC is offline   Reply With Quote
Old 01-10-2011, 05:47 AM   PM User | #9
cineweekly.com
Regular Coder

 
cineweekly.com's Avatar
 
Join Date: Aug 2010
Posts: 485
Thanks: 14
Thanked 3 Times in 3 Posts
cineweekly.com can only hope to improve
First option = same problem.

RewriteRule ^/(.*)$ /sunday/$1 = no error but urls are the same even after clearing cache etc. (so basically it doesn't do anything)

Third option = no error without your first code.
__________________
¿¿¿ curious ???
cineweekly.com is offline   Reply With Quote
Old 01-10-2011, 06:03 AM   PM User | #10
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
Unfortunately none of my tests cleared your problem and I can't devote any more time to it at the moment.

I did, however, find something that may help here: http://forum.modrewrite.com/viewtopic.php?f=3&t=6835

Try out some of those methods and post back. As soon as I get some more time I'll try some different methods. I'm surprised this is proving so difficult!
__________________
Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com
ShaneC is offline   Reply With Quote
Old 01-10-2011, 07:10 AM   PM User | #11
cineweekly.com
Regular Coder

 
cineweekly.com's Avatar
 
Join Date: Aug 2010
Posts: 485
Thanks: 14
Thanked 3 Times in 3 Posts
cineweekly.com can only hope to improve
I'll check the site out. Thanks for your help so far. My difficulty is I can't find anywhere to learn what ^ / $ (.) or the order of any of that does. I know * is a wild card but that's about it and it makes it impossible to play around with it.

EDIT: I'm sooooooo close now. The following changes my url:
root/sunday/file <--old url
root/file <--new url
Code:
RewriteRule ^sunday/(.*)$ /$1 [R=301,NC,L]
But it goes to a 404 page because the file really is in "root/sunday/file" I just want it to display as "root/file".
__________________
¿¿¿ curious ???
cineweekly.com is offline   Reply With Quote
Old 01-10-2011, 10:24 PM   PM User | #12
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
That actually isn't doing what you want it to do, I think.

What you have set up right now is a redirect. So it's redirecting from root/sunday/file to root/file. It's not, which I think you want it to, seeing root/file as the URL but looking in root/sunday/file for the file.

Am I correct in assuming that's what you want it to do?

I'll keep trying some more things. Here's a great reference for knowing what the ^, $, (.), etc do: http://www.addedbytes.com/cheat-shee...e-cheat-sheet/
__________________
Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com
ShaneC is offline   Reply With Quote
Old 01-11-2011, 05:06 AM   PM User | #13
cineweekly.com
Regular Coder

 
cineweekly.com's Avatar
 
Join Date: Aug 2010
Posts: 485
Thanks: 14
Thanked 3 Times in 3 Posts
cineweekly.com can only hope to improve
You're exactly right. That's why I tried removing the R=301 to see if you would just "rewrite" the displayed url. Thanks for the cheat sheet it clears up a lot.
__________________
¿¿¿ curious ???
cineweekly.com is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 AM.


Advertisement
Log in to turn off these ads.