Forum Moderators: phranque

Message Too Old, No Replies

Modify htaccess for local development server

         

jeremyt

1:05 pm on Dec 18, 2009 (gmt 0)

10+ Year Member



I am trying to modify my htaccess file so it will work locally on a development server. The internal ip address of the server is 192.168.2.9/PHP

I'm lost any help?

Here is our working htaccess for our domain:
<Files .htaccess>
order allow,deny
deny from all
</Files>

<IfModule mod_setenvif.c>
<IfDefine SSL>
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</IfDefine>
</ifmodule>

Options +FollowSymLinks
RewriteEngine On

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

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ [example.com...] [R=301,L]

# Externally redirect from non-www, non-canonical hostname to the
# canonical www hostname, preserving current HTTP/https protocol
# RewriteCond %{HTTP_HOST} !^www\.example\.com$
# RewriteCond %{SERVER_PORT}s ^(443(s)¦[0-9]+s)$
# RewriteRule (.*) http%2://www.example.com/$1 [R=301,L]

# old pages
RewriteCond %{REQUEST_FILENAME} how_do_work\.php
RewriteRule ^.+$ information.php?info_id=30&%{QUERY_STRING} [QSA,L] # Same below

RewriteCond %{REQUEST_FILENAME} blinking_body_lights.php
RewriteRule ^.+$ information.php?info_id=26&%{QUERY_STRING} [QSA,L]

RewriteCond %{REQUEST_FILENAME} glow_necklaces.php
RewriteRule ^.+$ information.php?info_id=27&%{QUERY_STRING} [QSA,L]

RewriteCond %{REQUEST_FILENAME} fundraising.php
RewriteRule ^.+$ information.php?info_id=31&%{QUERY_STRING} [QSA,L]

RewriteCond %{REQUEST_FILENAME} faq.php
RewriteRule ^.+$ faqdesk_index.php?%{QUERY_STRING} [QSA,L]

# default page with lang code
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/?$ index.php?language=$1&%{QUERY_STRING} [QSA,L]

# PHP pages with lang code
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]{2})/([_a-z\d]+\.php/?.*)$ $2?language=$1&%{QUERY_STRING} [QSA,L]

# information page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]?[a-z]?/?info/.+)\.html?$ information.php?info_name=$1&%{QUERY_STRING} [QSA,L]

# products info page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html?$ product_info.php?product_def=$1&%{QUERY_STRING} [QSA,L]

# categories path
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.htm$ index.php?cPath_name=$1&%{QUERY_STRING} [QSA,L]

# categories path
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ index.php?cPath_name=$1&%{QUERY_STRING} [QSA,L]

[edited by: jdMorgan at 7:36 pm (utc) on Dec. 18, 2009]
[edit reason] No URLs, please. See TOS and Charter. [/edit]

MrWumpus

6:24 pm on Dec 18, 2009 (gmt 0)

10+ Year Member



I'd like to know how to do this as well. Currently I just edit my hosts file and point the domain locally.

jdMorgan

7:48 pm on Dec 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Modifying your hosts file is the most efficient and safest method, but you could define a user variable containing the hostname, and refer to that instead of using a hard-coded hostname in the RewriteRule substitution addresses. See the [E=var:val] flag for rewriterule.

However, be aware that there is no native mod_rewrite support for comparing a variable to a variable, so any checks for specific hostnames will have to remain hard-coded -- again, see the 'hosts file' method above. :)

Be aware that the last six rules of your code result in seven calls to the operating system to go check the disk to see if the files or directories exist. You may expect several disk replacements and a server upgrade a couple of years early due to this wasteful coding construct. server performance may be noticieably slower, since disk access is typically thousands of times slower that code execution...

Consider combining the checks for the same filetypes and saving the result in a local variable (as previously described). Make the conditions under which any of these filechecks will be performed as restrictive as possible (make the rule patterns *very* specific), and use additional RewriteConds where needed and possible to exclude all previously-rewritten file-paths from being checked themselves, as a second pass through these filechecks will otherwise occur.

Jim