The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> Apache Development
|
Mod_rewrite assistance
Discuss Mod_rewrite assistance in the Apache Development forum on Dev Shed. Mod_rewrite assistance Apache Development forum discussing HTTP Server general topics, configuration, and modules. Apache is an open source web server that runs on multiple platforms.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 15th, 2012, 03:10 PM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
|
Mod_rewrite assistance
Hello everyone,
mod_rewrite is enabled and working.
Joomla is installed under "example.com/_usr/example1". What I would like to achieve is to never have the public see "_usr/example1" anymore, so just "example.com" and of course any trailing pages that I create in the future.
End result = Removal of "_usr/example1".
I tried the following code, but it never worked and I'm sure I'm far off from the solution.
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^_usr/example1/ http://example.com/? [R=301,L]
Any assistance would be greatly appreciated!
|

September 15th, 2012, 04:33 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Can't you just change the virtualhost (or regular host) to use that as the document root instead?
|

September 15th, 2012, 04:40 PM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
|
Good question, but no unfortunately. I am able to do it for all except this one as this one is the main host.
|

September 15th, 2012, 08:48 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Have it rewrite everything into that directory (except for stuff actually in that directory); what you have now tries to rewrite out of it.
Code:
RewriteRule ^(?!_usr/example1) _usr/example1${REQUEST_URI} [L]
|

September 16th, 2012, 11:33 AM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
No go sorry...
Code:
Not Found
The requested URL /_usr/example1${REQUEST_URI} was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
|

September 16th, 2012, 07:15 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
That $ should be a %. Damn Apache and it doing variables in a weird way.
|

September 16th, 2012, 09:08 PM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
Thanks requinix, but unfortunately its still not working. Below is the code I used to confirm... Is there a condition I should be using with this rule? Sorry, this is all new to me so its a lot to take in.
Code:
RewriteRule ^(%!_usr/example1) _usr/example1${REQUEST_URI} [L]
|

September 16th, 2012, 11:04 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
I don't know what you did there so lemme just post the correct version.
Code:
RewriteRule ^(?!_usr/example1) _usr/example1%{REQUEST_URI} [L]
|

September 17th, 2012, 06:10 AM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
|
Hmmm it never liked that very much... Shot out a 500 Internal Error. Do you think the problem could be with Joomla? I enabled both of the required fields, SEO URLs and URL ReWriting.
|

September 17th, 2012, 11:23 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Have you checked the error logs to see what is causing the 500s?
|

September 17th, 2012, 07:24 PM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
|
This may be a silly question, but should I be placing the .htaccess file under the root of "example.com" or under "example.com/_usr/example1"?
As of now I have the root (example.com) setup to redirect it over to (example.com/_usr/example1), and then the under (example.com/_usr/example1) I have your code.
|

September 17th, 2012, 07:44 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
What it's changing is how the root of the website behaves so the code should go in the root .htaccess. But putting it somewhere else shouldn't cause a 500 (it just wouldn't do any rewriting) so still check the logs.
So how it goes is like this:
1. User goes to example.com/some/path
2. The root .htaccess has a RewriteRule which says
Quote: | Anything that doesn't start with "_usr/example1" should be rewritten as "_usr/example1" + the original request path. |
3. The new URL is now example.com/_usr/example1/some/path
4? The root .htaccess has that same RewriteRule, but this time the path does start with "_usr/example1" so nothing happens
5. Joomla has its own URL rewriting scheme which turns the relative "/some/path" into something (such as index.php?path=some/path)
#4 may not happen, I'm still unsure how the whole process works and how [L] and [N] affect it.
Note how there isn't any re directing, just re writing. The former will actually send the user someplace while the latter happens behind the scenes.
|

September 17th, 2012, 08:27 PM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
|
Very well written requinix,
My apologies if I explained my issue improperly. What I need may be the oposite of what you have offered. I'm trying to figure out how to have it setup as "example.com/some/path". Currently is works as "example.com/_usr/example1/some/path".
See, its installed under "example.com/_usr/example1" but I wish to have it displayed to the public as if it was installed under "example.com".
|

September 17th, 2012, 09:37 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Yeah... That's what I've been going with so far. Everything I've said and posted is for that idea.
The user will still see example.com/some/path but Apache and Joomla will see it as example.com/_usr/example1/some/path. That's how URL rewriting works.
|

September 18th, 2012, 06:43 AM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 50
Time spent in forums: 12 h 7 m 53 sec
Reputation Power: 0
|
|
Here is my .htaccess code within the root (/) directory.
Code:
# Begin default subdomain redirect # RewriteEngine on # End default subdomain redirect # <Files *> # Begin varnish cache - disables server cache # Header set Cache-Control: "private, pre-check=0, post-check=0, max-age=0" Header set Expires: 0 Header set Pragma: no-cache # End varnish cache # </Files> # Modify the RewriteBase if you are using Joomla in a subdirectory or in a # VirtualDocumentRoot and the rewrite rules are not working properly. # For example if your site is at http://example.com/joomla uncomment and # modify the following line: RewriteBase / RewriteRule ^(?!_usr/example1) _usr/example1%{REQUEST_URI} [L]
Here is the Error Log
Code:
[Tue Sep 18 03:49:09 2012] [error] [client 184.171.206.20] File does not exist: /var/chroot/home/content/87/9580087/html/_usr/example1/missing.html [Tue Sep 18 04:31:31 2012] [error] [client 76.11.82.16] File does not exist: /var/chroot/home/content/87/9580087/html/_usr/example1/_usr [Tue Sep 18 04:31:31 2012] [error] [client 76.11.82.16] File does not exist: /var/chroot/home/content/87/9580087/html/_usr/example1/_usr [Tue Sep 18 04:31:38 2012] [error] [client 76.11.82.16] File does not exist: /var/chroot/home/content/87/9580087/html/_usr/example1/_usr [Tue Sep 18 04:31:38 2012] [error] [client 76.11.82.16] File does not exist: /var/chroot/home/content/87/9580087/html/_usr/example1/_usr
Last edited by Wayniac : September 18th, 2012 at 03:40 PM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|