?
Solved

Clean URLs (.htaccess / httpd.config)

Posted on 2007-03-21
5
Medium Priority
?
296 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 real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 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