I recently found a bug that when i go to example.com/phpmyadmin or example.com/index the trailing slash gets removed, so it's calling example.comphpadmin or example.comindex. This happens with everything after the slash. But if i have a second trailing slash like example.com/index/home it works perfectly.
I have a redirect from http to https active in my site config, running apache2.4.
My config:
<VirtualHost *:80>
ServerName example.net
Redirect permanent / https://example.net
</VirtualHost>
And my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(phpmyadmin|index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I looked around but found no answers. Maybe there is something wrong with my config and somebody could help me.
Considering that this RewriteRule doesn't even execute for /phpmyadmin due to the RewriteCond, and the RewritRule doesn't redirect, the problem is a bug in whoevers index.php you're sending all the unknown resources to.
Or, you've not shown us the actual configuration.
I was being dumb and just had to clear the cache to get it working. I don't know what exactly wasn't working but my changes i made before making this post did work out, just the cache still had the faulty version in it.
Related
I have a url, lets say its blog.art.ca/Customer/AAAABBBB/index.html
and I want to hide Customer and AAAABBBB. Now AAAABBBB can be any 8 character alphanumeric code.
Options +FollowSymLinks -Multiviews -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Customer/(.*)$ /$1 [L,R]
</IfModule>
I've tried numerous things, however, I either get ERR_TOO_MANY_REDIRECTS or it just causes the server to crash. Any suggestions would be much appreciated!
You still need to allow the requests to reach the actual requested resources, so you'll need two sets of rules, one to the browser, to show the new shorter URL (301 permanent redirect), and a second set to undo this mapping back to the original URL, so that Apache can find the right stuff to serve eg.
RewriteBase /
# Remove Customer/AAAABBB from the URL shown in the browser.
RewriteCond %{QUERY_STRING} !customer=
RewriteRule ^Customer/([^/]+)/(.*) /$2?customer=$1 [L,QSA,R=301]
# Internally undo any masked rewrites.
RewriteCond %{QUERY_STRING} customer=([^&]+)
RewriteRule (.*) /Customer/%1/$1 [L]
The following .htaccess was able to allow my symfony project domain to be served without app.php in the URL, as intended. The only issue is that it is breaking all other (non-symfony related) urls and causing an internal server error.
Right now, after deleting the .htaccess file from the server, all my domains work but the project tied to symfony must be accessed using app.php in URL ?
Is it possible to modify the below .htaccess to rewrite the symfony url to not require app.php in the URL while still allowing for all other URLs, not tied to symfony, to be accessed successfully?
Not sure this is needed, but assume the domain tied to symfony is www.apples.com.
Thanks in advance!
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
Edit
I also tried the following:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change below before deploying to production
RewriteRule ^(.*)$ app.php [QSA,L]
DirectoryIndex index.php
</IfModule>
Right after
RewriteCond %{REQUEST_FILENAME} !-f
add
RewriteCond %{REQUEST_FILENAME} !-d
and set DirectoryIndex to index.php
A bit late to this game but I just found an Apache directive that saves so much time and makes your htaccess cleaner. The only caveat is you must have Apache 2.2.16+. To have all urls except valid files (images, etc) use app.php as a front controller use the FallbackResource directive.
<Directory "/web/symfony-project">
FallbackResource /app.php
</Directory>
I know this has been asked many times, but something strange is happening to me. Apache DocumentRoot is pointing to symfony/web/ and this is my .htaccess inside web/ dir:
DirectoryIndex app_dev.php
#DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
#RewriteRule ^(.*)$ app.php [QSA,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Well, the thing is www.example.com/route1/ is working and www.example.com/route2/ is throwing an error:
Oops! An Error Occurred
The server returned a "404 Not Found".
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
While www.example.com/app_dev.php/route2/ is working ok (also www.example.com/app_dev.php/route1/)
Help?
Update. Cache clear in prod throws this error (I never tried before, I'm working on dev):
[Doctrine\Common\Proxy\Exception\UnexpectedValueException]
The type hint of parameter "userRoles" in method "addRole" in class "MyProject\PanelBundle\Entity\User" is invalid.
[ReflectionException]
Class Maycol\BlogBundle\Entity\Role does not exist
This is the .htaccess that worked for me:
DirectoryIndex app.php
#DirectoryIndex app_dev.php
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the startpage because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteRule ^app_dev\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteCond %{REQUEST_FILENAME} -f
#RewriteRule ^(.*)$ app_dev.php [QSA,L]
RewriteRule ^(.*)$ app.php [QSA,L]
# The following rewrites all other queries to the front controller. The
# condition ensures that if you are using Apache aliases to do mass virtual
# hosting, the base path will be prepended to allow proper resolution of the
# app.php file; it will work in non-aliased environments as well, providing
# a safe, one-size fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
#RewriteRule .? %{ENV:BASE}app_dev.php [L]
RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the startpage to the front controller explicitly so that the website
# and the generated links can still be used.
#RedirectMatch 302 ^/$ /app_dev.php/
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
This error is NOT Apache/htaccess related. This 404 error page is the default one of symfony itself!
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
There is no route matching /route2. Check your routing like this:
php app/console router:debug
To inspect it quicker use grep or findstr ( Windows )
php app/console router:debug | grep route2
Please also check that your route is not only configured in the dev environment ( i.e. only in routing_dev.yml )!
php app/console router:debug --env=prod
please clear your prodution cache with ...
php app/console cache:clear --env=prod
... and check your log files if there is an uncaught Exception leading to the 404 page displayed when accessing the page. You can for example use this command to view the live changes in the production logfile.
tail -f app/logs/prod.log
i have a .htacces on my server that is supposed to do this:
yo enter to ziced.com/cl/something and rewrites it as ziced.com/cl/index.php?var1=something, however is not working.
you can check that is not working by entering ziced.com/cl/faq versus ziced.com/cl/index.php?var1=faq
here is the .htaccess
AddHandler application/x-httpd-php5 .php
# This is the initialization
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
#Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
#chilean redirect
# /cl/var1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cl/([a-zA-Z0-9\.\*\°\~\,\%\"\'\+\(\)\-]+)/?$ /cl/index.php?var1=$1 [L,QSA]
I might know what the problem is but i dont know how to fix it. The webpage that has the rewrite rule, ziced.com, is an addondomain of metrikstudios.com
ziced.com points to metrikstudios.com/ziced/ so, maybe i should add something like:
RewriteRule ^ziced/cl/([a-zA-Z0-9\.\*\°\~\,\%\"\'\+\(\)\-]+)/?$ /cl/index.php?var1=$1 [L,QSA]
Solved the problem. Added the .htacces inside the subdirectory ziced (metrikstudios.com/ziced). Then it worked perfect.
Hope it works for someone in the future
I have WAMP v2.2 installed on my Windows 7 machine, with virtual hosts enabled.
I've successfully installed ExpressionEngine for one of my local sites, and everything works great except when I try to remove index.php from the URL using the approved .htaccess method. I still get a 404 error if index.php is not present, but the page displays fine with index.php in the URL.
I made sure the rewrite module was checked in the Apache menu:
. I've successfully used this method dozens of times on commercial hosts, so I'm stumped.
Update for pvledoux:
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# If 404s, "No Input File" or every URL returns the same thing
# make it /index.php?/$1 above (add the question mark)
</IfModule>
Note: I tried adding the ? into the rule, but it didn't work.
The site is at the root of the Virtual Host.
Got It!
I needed to add AllowOverride in httpd-vhosts.conf:
<Directory "C:\Site\Root\Path">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
A gagillion thanks and a 6-pack of beer goes to #parhamr for helping me out of this pickle.
A few possibilities here you could try out here:
[...]
RewriteEngine On
Options FollowSymLinks
[...]
Or:
[...]
RewriteEngine On
Options +MultiViews
[...]
Or:
[...]
RewriteEngine On
Options FollowSymLinks
Options +MultiViews
[...]
From my experience, Apache when running on Windows often needs one or both of those in order to do these kinds of things correctly. It might also straight up 500 on you, but these have worked for me in the past.
try to add RewriteBase /
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# If 404s, "No Input File" or every URL returns the same thing
# make it /index.php?/$1 above (add the question mark)
</IfModule>
and check for sure that mod_rewrite is active in phpinfo
Have you checked your default document in Apache? If you are removing index.php physically from the machine and it reports a 404 on just a directory, www.domain.com/home/ that means Apache is looking for index.php still.
Is mod_rewrite turned on in the Apache?