• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Questions about my .htaccess

#1
[eluser]skunkbad[/eluser]
Last night I decided that I'd take the file extension off of the pages on my website. I wanted to use 301 redirects for each of these pages, and have successfully done so, but wondering about the L on each line 31 through 41, and if the whole .htaccess file looks OK or not. Everything works, except the host has been complaining about CPU and memory usage. Trying not to leave any stones uncovered.

Code:
# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

# Protect application and system files from being viewed
RewriteRule ^(system|application) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^portfolio.php [NC]
RewriteCond %{REQUEST_FILENAME} !^development.php [NC]
RewriteCond %{REQUEST_FILENAME} !^about.php [NC]
RewriteCond %{REQUEST_FILENAME} !^faq.php [NC]
RewriteCond %{REQUEST_FILENAME} !^contact.php [NC]
RewriteCond %{REQUEST_FILENAME} !^estimates.php [NC]
RewriteCond %{REQUEST_FILENAME} !^templates.php [NC]
RewriteCond %{REQUEST_FILENAME} !^accessibility.php [NC]
RewriteCond %{REQUEST_FILENAME} !^privacy.php [NC]
RewriteCond %{REQUEST_FILENAME} !^terms.php [NC]
RewriteCond %{REQUEST_FILENAME} !^sitemap.php [NC]

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

RewriteRule /portfolio.php http://www.mysite.com/portfolio [R=301,L]
RewriteRule /development.php http://www.mysite.com/development [R=301,L]
RewriteRule /about.php http://www.mysite.com/about [R=301,L]
RewriteRule /faq.php http://www.mysite.com/faq [R=301,L]
RewriteRule /contact.php http://www.mysite.com/contact [R=301,L]
RewriteRule /estimates.php http://www.mysite.com/estimates [R=301,L]
RewriteRule /templates.php http://www.mysite.com/templates [R=301,L]
RewriteRule /accessibility.php http://www.mysite.com/accessibility [R=301,L]
RewriteRule /privacy.php http://www.mysite.com/privacy [R=301,L]
RewriteRule /terms.php http://www.mysite.com/terms [R=301,L]
RewriteRule /sitemap.php http://www.mysite.com/sitemap [R=301,L]

Options -Indexes

#2
[eluser]Phil Sturgeon[/eluser]
Quote:# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

# Protect application and system files from being viewed
RewriteRule ^(system|application) - [F,L]

RewriteRule /portfolio.php /portfolio [R=301,L]
RewriteRule /development.php /development [R=301,L]
RewriteRule /about.php /about [R=301,L]
RewriteRule /faq.php /faq [R=301,L]
RewriteRule /contact.php /contact [R=301,L]
RewriteRule /estimates.php /estimates [R=301,L]
RewriteRule /templates.php /templates [R=301,L]
RewriteRule /accessibility.php /accessibility [R=301,L]
RewriteRule /privacy.php /privacy [R=301,L]
RewriteRule /terms.php /terms [R=301,L]
RewriteRule /sitemap.php /sitemap [R=301,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

or

Quote:# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

# Protect application and system files from being viewed
RewriteRule ^(system|application) - [F,L]

# Redirect all old .php links
RewriteRule ^/([a-z_])(.php) /$1 [R=301,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

#3
[eluser]skunkbad[/eluser]
Phil, thanks for the 2 examples. Do you think my version would cause the server to use more CPU or memory?

#4
[eluser]Phil Sturgeon[/eluser]
Generally speaking more rules means more memory. Obviously a few simple rules will be quicker than a really damn complicated rule, but in this example it should be quicker.

If you are really worried about CPU and memory useage then you really should put these rules into Apache config as that is loaded into memory once and used every time whereas .htaccess is read and parsed on each request.

#5
[eluser]skunkbad[/eluser]
For whatever reason, neither of the code examples shown would work. They just resulted in 404 errors if I tried to go to a page and used the .php file extension.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.