Forum Moderators: phranque
I am a PHP developer but I dont have expertise in apache and mod_rewrite.
I am using the following rewrite code for my website this code is placed in .htaccess file.
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
# comment the following 3 lines to allow periods in routes
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
# big crash from our front web controller
ErrorDocument 500 "<h2>Application error</h2>symfony application failed to start properly"
This code is working perfectly fine on my local machine but not with remote server because server has different port that is 8080.
Can anyone alter this code for me so that it will work with my server machine.
Thanks
Please describe how you are testing, what URLs you are typing in, what the expected results are, what the actual results are, and how the actual results differ from the expected results. Also include any relevant information from your server error log file.
As stated in our forum charter, we cannot write your code for you, but we can help *you* get *your* code working. This code needs several improvements, but the problems are minor and do not appear to be 'fatal' problems.
Jim
server machine url: [website_name:8080...]
this will render page not found error
local machine url: [website_name...]
this will show a home page.
It's likely that "noscriptname" or your app server (or something else) just isn't set up to work on a non-standard port -- i.e. anything but port 80. You might want to use a server headers checker to see if port 8080 requests are being redirected to port 80 and therefore 'breaking' things, and also do check your server error log: It will often tell you exactly what is wrong.
The code above can be more-efficiently and more-robustly written as:
RewriteEngine On
#
# Skip following rules if final URL-path-part contains a period
# (i.e. contains a filetype), except for ".html"
# (Modified to allow periods anywhere except in final URL-path part)
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^([^/]+/)*([^.]+\.)+([^./])+$ - [L]
#
# Internally rewrite requests for extensionless URLs to add ".html"
RewriteRule ^(([^/]+/)*[^./]+)$ $1.html
#
# Internally rewrite index requests to index.html
RewriteRule ^$ index.html
#
# Internally rewrite to web controller if .html file does not exist
# (else the existing .html file will be served)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Note also that [QSA] is a waste of time unless you want to append new query data to the existing query data. If no new query data is included in the RewriteRule substitution, then the default behaviour is for all rules to simply pass the existing query string unchanged. Therefore [QSA] was not needed in any of these rules.
Jim