Solved

Clean URLs (.htaccess / httpd.config)

Posted on 2007-03-21
5
289 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
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:JamesCssl
Comment Utility
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
Comment Utility
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
Comment Utility
I believe that is correct.  You would put it in whichever VirtualHost you wanted it to apply to.
0
 

Author Comment

by:MarcinKG
Comment Utility

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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now