?
Solved

Clean URLs (.htaccess / httpd.config)

Posted on 2007-03-21
5
Medium Priority
?
298 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 200 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

649 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