Solved

Clean URLs (.htaccess / httpd.config)

Posted on 2007-03-21
5
292 Views
Last Modified: 2007-03-22
I'd like to know if the following .htaccess can be written more efficiently.

I am hosting my site on VPS server - is it better to use .htaccess or include these rewrites in httpd.config?


RewriteEngine on
Options +FollowSymLinks

RewriteRule index.php - [L]

RewriteRule ^img/(.+)$ img/$1 [L]
RewriteRule ^css/(.+)$ css/$1 [L]
RewriteRule ^js/(.+)$ js/$1 [L]

//domain.com/shoes
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^(.[^/]*)[/]?$ /index.php?section=$1 [L,QSA]
RewriteRule ^(.[^/]*)[/]?$ /index.php?section=$1 [L,QSA]

//domain.com/en-us/shoes
#RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^(.[^/]*)/(.[^/]*)[/]?$ /index.php?section=$1&language=$2 [L,QSA]
0
Comment
Question by:MarcinKG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:JamesCssl
ID: 18768454
Since you have access to httpd.conf, it's better to place them there.  The server accesses this first, and is therefore faster.
0
 

Author Comment

by:MarcinKG
ID: 18768660
Where do I include the above code in httpd.config? Between <VirtualHost> tags?

<VirtualHost 11.11.111.11>

ServerAlias domain.com
ServerAdmin webmaster@domain.com
DocumentRoot /home/domain.com/public_html
BytesLog domlogs/domain.com-bytes_log

User user
Group group
ServerName www.domain.com

User user
Group group
CustomLog /usr/local/apache/domlogs/domain.com combined
ScriptAlias /cgi-bin/ /home/domain.com/public_html/cgi-bin/

</VirtualHost>
0
 
LVL 11

Expert Comment

by:JamesCssl
ID: 18768992
I believe that is correct.  You would put it in whichever VirtualHost you wanted it to apply to.
0
 

Author Comment

by:MarcinKG
ID: 18771786

Thanks JamesCssl

What about the following RewriteRule - can it be simplified or done in a better way? As you can tell I want to exclude paths to images/css/js from being rewritten.

RewriteRule ^img/(.+)$ img/$1 [L]
RewriteRule ^css/(.+)$ css/$1 [L]
RewriteRule ^js/(.+)$ js/$1 [L]
0
 
LVL 11

Accepted Solution

by:
JamesCssl earned 50 total points
ID: 18772008
You just want to basically let these specific ones pass through, right?  The way you are doing it sometimes produces a 500 Internal Server error.  Instead, you should do it like this to allow it to simply pass through:


RewriteRule ^img/(.+)$ - [L]
RewriteRule ^css/(.+)$ - [L]
RewriteRule ^js/(.+)$ - [L]
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Service "nameserver" appears to be down 4 662
Setting up a WAMP server... 7 68
Cpanel file manager 8 58
web server dns redirect 5 61
In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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