Solved

Clean URLs (.htaccess / httpd.config)

Posted on 2007-03-21
5
293 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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